HDU 4967 A simple water problem

来源:互联网 发布:cookie统计uv存数据 编辑:程序博客网 时间:2024/05/20 18:46
#include <cstdio>#include <iostream>#include <queue>using namespace std;void solve(){  priority_queue<int> mypq;  int n;  scanf("%d", &n);  for (int i = 0; i < n; i++)  {    int x;    scanf("%d", &x);    mypq.push(x);  }  int ans = 0;  while (!mypq.empty())  {    int a = mypq.top();    mypq.pop();    if (!mypq.empty())    {      int b = mypq.top();      mypq.pop();      ans += b;      a -= b;      if (a != 0) mypq.push(a);    }else    {      ans += a;    }  }  printf("%d\n", ans);}int main(){//  freopen("input.txt", "r", stdin);  int t;  scanf("%d", &t);  for (int i = 1; i <= t; i++)  {    cout << "Case #" << i << ": ";    solve();  }}
0 0
原创粉丝点击