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

不知道哪里错了,各位帮我看看.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:

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