• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LyonLys
愿意在角落唱沙哑的歌 再大声也都是给你 请用心听 不要说话 Contact me via E-mail: lyon.lys@gmail.com
博客园    首页    新随笔    联系   管理    订阅  订阅

hdu 2527 Safe Or Unsafe

Problem - 2527

  水题一枚,轻松通过。

代码如下:

View Code
 1 #pragma comment(linker, "/STACK:102400000,102400000")
 2 
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <vector>
 7 #include <algorithm>
 8 #include <set>
 9 #include <iostream>
10 #include <queue>
11 #include <map>
12 
13 using namespace std;
14 
15 #define REP(i, n) for (int i = 0; i < (n); i++)
16 #define REP_1(i, n) for (int i = 1; i <= (n); i++)
17 #define PB push_back
18 #define MPR make_pair
19 #define SZ(x) ((int) (x).size())
20 #define FI first
21 #define SE second
22 #define _clr(x) memset(x, 0, sizeof(x))
23 #define ALL(x) (x).begin(), (x).end()
24 #define PRIQ priority_queue
25 
26 typedef vector<int> VI;
27 typedef pair<int, int> PII;
28 typedef vector<PII> VPII;
29 
30 const int N = 1e5 + 100;
31 
32 PRIQ<PII, VPII, greater<PII> > Q;
33 int cnt[26];
34 
35 int work(char *str) {
36     _clr(cnt);
37     while (*str) cnt[*(str++) - 'a']++;
38     while (!Q.empty()) Q.pop();
39     REP(i, 26) {
40         if (cnt[i]) Q.push(MPR(cnt[i], 0));
41     }
42     PII a, b;
43     int fi, se;
44     while (Q.size() > 1) {
45         a = Q.top();
46         Q.pop();
47         b = Q.top();
48         Q.pop();
49         se = (a.SE ? a.SE : a.FI) + (b.SE ? b.SE : b.FI);
50         fi = a.FI + b.FI + a.SE + b.SE;
51         Q.push(MPR(fi, se));
52     }
53     return Q.top().FI;
54 }
55 
56 char buf[10000];
57 
58 int main() {
59     int T, n;
60     cin >> T;
61     REP(i, T) {
62         cin >> n >> buf;
63 //        cout << work(buf) << endl;
64         cout << ((n < work(buf)) ? "no" : "yes") << endl;
65     }
66     return 0;
67 }

 

——written by Lyon

posted @ 2013-03-22 23:59  LyonLys  阅读(197)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3