标签:class blog code 2014 os name
#include<iostream> #include<queue> using namespace std; #define read(x) scanf("%lld",&x) int main() { priority_queue<long long,vector<long long>,greater<long long> >q; long long n,temp,sum; read(n); if(n==1) { read(temp); printf("%lld\n",temp); return 0; } while(n--) { read(temp); q.push(temp); } sum=0; while(q.size()>1) { temp=q.top(); q.pop(); temp+=q.top(); q.pop(); sum+=temp; q.push(temp); } printf("%lld\n",sum); }小顶堆实现哈夫曼树
标签:class blog code 2014 os name
原文地址:http://blog.csdn.net/stl112514/article/details/30534111