首页 > 其他 > 详细

51NOD 1117 聪明的木匠

时间:2017-08-12 16:45:39      阅读:333      评论:0      收藏:0      [点我收藏+]

来源: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 聪明的木匠

原文:http://www.cnblogs.com/Draymonder/p/7350625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!