水题。
#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 模拟(水
时间: 2024-10-10 05:09:02