1. 程式人生 > >51NOD 1117 聰明的木匠

51NOD 1117 聰明的木匠

每次 i++ color += can bit ++ pac nbsp

來源: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 聰明的木匠