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

## 不知道哪里错了,各位帮我看看.1339

Posted by Grope at 2003-10-14 06:21:35 on Problem 1339
```#include<iostream.h>
unsigned long card[100001];
long m,n;
void heapify(long i){
unsigned long l,r,small,temp;
l=2*i-1;
r=2*i;
if(l<=n&&card[l]<=card[i])
small=l;
else small=i;
if(r<=n&&card[r]<=card[i])
small=r;
if(small!=i){
temp=card[i];
card[i]=card[small];
card[small]=temp;
heapify(small);
}
}

void build(){
long int i;
for(i=n;i>0;i--)
heapify(i);
}
int main()
{
unsigned long t,i,j,k,s1,s2;
unsigned long point;
cin>>t;
while(t--){
cin>>m;
n=m;
for(i=1;i<=m;i++)
cin>>card[i];
build();
point=0;
if(n==1) point=card[1];
while(n>1){
s1=card[1];
card[1]=card[n];
n--;
heapify(1);
s2=card[1];
point+=s1+s2;
card[1]=s1+s2;
heapify(1);
}
cout<<point<<endl;
}
return 1;
}
```

Followed by: