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

代码,献给像我一样WA好多次的同志们

Posted by schindlerlee at 2008-07-27 10:54:07 on Problem 3253
#include<iostream>
#include<algorithm>
using namespace std;

#define N 20005
//20005
bool cmp(int a,int b)
{
	return a>b;
}

int main()
{
	int n;
	int i;
	int fenc[N];

	__int64 sum;

	while(	scanf("%d",&n)!=EOF  )
	{		
		for(i=0;i<n;i++)
		{
			scanf("%d",&fenc[i]);
		}
		if (1==n)
		{
			printf("0\n");
			continue;
		}
		sum=0;

		make_heap(fenc,fenc+n,cmp);
		for(i=n;i>1;i--)
		{
			pop_heap(fenc,fenc+i,cmp);
			sum+=fenc[i-1];
			pop_heap(fenc,fenc+i-1,cmp);
			sum+=fenc[i-2];

			fenc[i-2]+=fenc[i-1];
			push_heap(fenc,fenc+i-1,cmp);
		}
		printf("%I64d\n",sum);
		
		
	}
	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