HDU 4974 A simple water problem 模拟(水

来源:互联网 发布:尉迟琳嘉 知乎 编辑:程序博客网 时间:2024/05/20 18:50

水题。

#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;}


0 0
原创粉丝点击