#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();
}
}
HDU 4967 A simple water problem
最新推荐文章于 2020-02-07 11:05:28 发布
本文深入探讨了使用C++实现的优先队列算法,详细解释了如何通过优先队列进行数据处理,包括数据的输入、排序及计算过程。文章通过具体实例展示了优先队列在解决特定问题中的应用,为读者提供了理解和运用此算法的清晰路径。
3978

被折叠的 条评论
为什么被折叠?



