标签:os io for amp size sp on ef
水题。
#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; }
HDU 4974 A simple water problem 模拟(水,布布扣,bubuko.com
HDU 4974 A simple water problem 模拟(水
标签:os io for amp size sp on ef
原文地址:http://blog.csdn.net/qq574857122/article/details/38734179