当前位置: 代码迷 >> 综合 >> POJ - 3253 Fence Repair(优先队列)
  详细解决方案

POJ - 3253 Fence Repair(优先队列)

热度:18   发布时间:2023-11-25 08:38:09.0

POJ - 3253 Fence Repair

#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
    int n;while(scanf("%d",&n)!=EOF){
    priority_queue<ll,vector<ll>,greater<ll>>q;//最小优先for(int i=0;i<n;++i){
    int x;scanf("%d",&x);q.push(x);}ll sum=0;while(!q.empty()){
    int a=q.top();q.pop();int b=q.top();q.pop();sum=sum+a+b;if(q.empty()) break;q.push(a+b);}printf("%lld\n",sum);}return 0;
}
  相关解决方案