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

为什么会错呢?该怎么贪心呢?

Posted by yiyiyi4321 at 2006-03-25 21:25:08 on Problem 2782
#include<stdio.h>

long used[10001];

int main()
{
	long i,j,n,ans;
	int bin,m;

	scanf("%ld",&n);
	memset(used,0,sizeof(used));
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		used[m]++;
	}
	ans=0;
	ans+=used[bin];
	for(i=bin-1;i>=0;i--)
	{
		while(used[i])
		{
			used[i]--;
			ans++;
			for(j=bin-i>i?i:bin-i;j>=0;j--)
				if(used[j])break;
			if(j>=0)used[j]--;
		}
	}
	printf("%ld\n",ans);
	
	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