51NOD 1117 聪明的木匠

来源: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=;i<n;i++){
int x;scanf("%d",&x);
Q.push(x);
}
long long sum = ;
while (Q.size()> ){
int t1 = Q.top();Q.pop();
int t2 = Q.top();Q.pop();
sum += t1+t2;
Q.push(t1+t2);
}
printf("%lld",sum);
}
上一篇:iOS中UIWebView使用JS交互


下一篇:vba 笔记