Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

数据类型。。。long long long long long long long long

Posted by lvweihua at 2017-08-20 14:51:58 on Problem 3253
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator