hdu 2527 Safe Or Unsafe
2013-03-22 23:59
288 查看
Problem - 2527
水题一枚,轻松通过。
代码如下:
View Code
——written by Lyon
水题一枚,轻松通过。
代码如下:
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
相关文章推荐
- HDU 2527 Safe Or Unsafe
- hdu 2527 Safe Or Unsafe(哈夫曼编码)
- HDU 2527 Safe Or Unsafe【哈夫曼编码】
- HDU 2527 Safe Or Unsafe
- hdu 2527 Safe Or Unsafe(哈夫曼编码)
- HDU 2527 Safe Or Unsafe(哈夫曼编码)
- hdu 2527 Safe Or Unsafe<multiset>
- Hdu 2527 Safe Or Unsafe
- HDU 2527 Safe Or Unsafe (哈夫曼树)
- HDU 2527 Safe Or Unsafe(哈夫曼编码)
- hdu 2527 Safe Or Unsafe(优先队列+哈夫曼树)
- hdu 2527 Safe Or Unsafe(霍夫曼树)
- hdu 2527:Safe Or Unsafe(数据结构,哈夫曼树,求WPL)
- hdu 2527 Safe Or Unsafe (哈夫曼树)
- HDU 2527 Safe Or Unsafe
- hdu 5.2.8 2527 safe or unsafe
- hdu 2527 Safe Or Unsafe
- HDU 2527 Safe Or Unsafe 【Huffman编码】
- Hdu 2527 Safe Or Unsafe-哈夫曼编码+优先队列
- hdoj 2527 Safe Or Unsafe 【huffman编码】