标签:www pop main 来源 top log question printf bit
来源: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); }
标签:www pop main 来源 top log question printf bit
原文地址:http://www.cnblogs.com/Draymonder/p/7350625.html