您的位置:首页 > Web前端

hdu 2527 Safe Or Unsafe

2013-03-22 23:59 288 查看
Problem - 2527

  水题一枚,轻松通过。

代码如下:

View Code

#pragma comment(linker, "/STACK:102400000,102400000")

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
#include <queue>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP_1(i, n) for (int i = 1; i <= (n); i++)
#define PB push_back
#define MPR make_pair
#define SZ(x) ((int) (x).size())
#define FI first
#define SE second
#define _clr(x) memset(x, 0, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define PRIQ priority_queue

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

const int N = 1e5 + 100;

PRIQ<PII, VPII, greater<PII> > Q;
int cnt[26];

int work(char *str) {
_clr(cnt);
while (*str) cnt[*(str++) - 'a']++;
while (!Q.empty()) Q.pop();
REP(i, 26) {
if (cnt[i]) Q.push(MPR(cnt[i], 0));
}
PII a, b;
int fi, se;
while (Q.size() > 1) {
a = Q.top();
Q.pop();
b = Q.top();
Q.pop();
se = (a.SE ? a.SE : a.FI) + (b.SE ? b.SE : b.FI);
fi = a.FI + b.FI + a.SE + b.SE;
Q.push(MPR(fi, se));
}
return Q.top().FI;
}

char buf[10000];

int main() {
int T, n;
cin >> T;
REP(i, T) {
cin >> n >> buf;
//        cout << work(buf) << endl;
cout << ((n < work(buf)) ? "no" : "yes") << endl;
}
return 0;
}


——written by Lyon
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: