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 |
不知道哪里错了,各位帮我看看.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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator