POJ - 3253 Fence Repair
https://vjudge.net/problem/POJ-3253
和合并果子的题一样
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int n,x;
long long ans;
while(~scanf("%d",&n))
{
priority_queue<int,vector<int>,greater<int> > q;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
q.push(x);
}
int a,b;
ans=0;
while(q.size()>=2)
{
a=q.top();
q.pop();
b=q.top();
q.pop();
ans+=a+b;
q.push(a+b);
}
printf("%lld\n",ans);
}
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483297.html

浙公网安备 33010602011771号