首页 > 代码库 > 51NOD 1117 聪明的木匠

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=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);}

 

51NOD 1117 聪明的木匠