| ||||||||||
| 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 | |||||||||
好长~~In Reply To:Re:我的ac代码,纯c 16ms 共同学习 Posted by:sunkehappy at 2009-03-15 15:24:58 #include<iostream>
#include<fstream>
#include<queue>
using namespace std;
struct aa
{long long n;};
bool operator<(aa a,aa b)
{
return a.n>b.n;
}
int main()
{
//ifstream cin("0.txt");
priority_queue<aa>q;aa y;
long long n,i,t;cin>>n;
for(i=0;i<n;i++)
{
cin>>t;y.n=t;
q.push(y);
}
if(n==1)
cout<<0<<endl;
else
{
long long sum=0;
while(q.size()>1)
{
long long a,b;
y=q.top();
a=y.n;
q.pop();
y=q.top();
b=y.n;
q.pop();
sum+=a+b;
y.n=a+b;
q.push(y);
}
cout<<sum<<endl;
}
//system("pause");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator