哈夫曼树
搬水果
http://www.nowcoder.com/questionTerminal/e4c775b0f3ee42a4bb72c26d2e1eef8a
#include <iostream> #include <queue> using namespace std; int main() { int n,ans,a,b,x; while(scanf("%d",&n)!=EOF&&n!=0) { priority_queue<int,vector<int>,greater<int>> myQueue; //优先队列 while(n--) { scanf("%d",&x); myQueue.push(x); } ans = 0; while(myQueue.size()>1) { a=myQueue.top(); myQueue.pop(); b=myQueue.top(); myQueue.pop(); ans+=a+b; myQueue.push(a+b); } printf("%d\n",ans); } return 0; }(•̀ᴗ•́)و