您的位置:首页 > 其它

HDU 4974 A simple water problem 模拟(水

2014-08-21 17:51 323 查看
水题。

#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
priority_queue<int> q;
int main() {
    int T, cas = 0;
    scanf("%d", &T);
    while(T-- > 0) {
        int n;
        scanf("%d", &n);
        for(int i = 0, x; i < n; i ++) {
            scanf("%d", &x);
            q.push(x);
        }
        ll ans = 0;
        while(!q.empty()) {
            if(q.size() >= 2) {
                int x = q.top(); q.pop();
                int y = q.top(); q.pop();
//                printf("%d %d\n", x, y);
                ans += y;
                q.push(x-y);
            } else {
                ans += q.top();
                q.pop();
            }
        }
        printf("Case #%d: ", ++cas);
        cout << ans << endl;
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: