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 doner at 2008-10-20 09:43:20 on Problem 2782
#include<stdio.h>
#include<stdlib.h>
int compare(const void * arg1,const void * arg2);
int main()
{
	int a[100005];
	int flag[100005];
	int i,n,len,j,result;
	result=0;
	scanf("%d%d",&n,&len);
	if(n<0||n>100000||len>10000)return 0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		flag[i]=0;
	}
	qsort(a,n,sizeof(int),compare);
	j=0;
	for(i=0;i<n;i++)
	{
		if(flag[i]==1)continue;
		for(j=i+1;j<n;j++)
		{
			if(flag[j]==0&&a[i]+a[j]<=len)
			{
				flag[j]=1;
				break;
			}
		}
		flag[i]=1;
		result++;
	}
	printf("%d",result);
	return 0;
}
int compare(const void * arg1,const void * arg2)
{
	return (*((int *)arg1))<(*((int *)arg2))?1: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