您的位置:首页 > 其它

51NOD 1117 聪明的木匠

2018-02-09 18:00 309 查看
来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1117

 

挑战原题吧  大概

每次挑选最小的两个,合起来

 

#include <bits/stdc++.h>
using namespace std;

int main ()
{
int n;
scanf("%d",&n);
priority_queue<int,vector<int>,greater<int> > Q;
for(int i=0;i<n;i++){
int x;scanf("%d",&x);
Q.push(x);
}
long long sum = 0;
while (Q.size()> 1){
int t1 = Q.top();Q.pop();
int t2 = Q.top();Q.pop();
sum += t1+t2;
Q.push(t1+t2);
}
printf("%lld",sum);
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: