| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
数据类型。。。long long long long long long long long#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=20005;
typedef long long LL;
LL P[MAXN];
int N;
LL Huffman(){
priority_queue<LL,vector<LL>,greater<LL>>Q; //最小堆
memset(P,0,sizeof(P));
for(int i=0;i<N;i++){
scanf("%lld",&P[i]);
Q.push(P[i]);
}
LL ans=0;
while(Q.size()>1){
LL a=Q.top();Q.pop();
LL b=Q.top();Q.pop();
ans+=(a+b);
Q.push(a+b);
}
return ans;
}
int main(){
while(scanf("%d",&N)!=EOF){
printf("%lld\n",Huffman());
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator