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呢?我测试了N多的数据了!!!(程序)help!!!

Posted by hujk2008 at 2004-07-07 03:45:03 on Problem 1011
#include<stdio.h>
#include<stdlib.h>

#define max 300

int a[max]={0},b[max]={0},flag=0,n=0,k=0,FF=0;

int cmp(const void * x,const void * y)
{
	int * p,*q;
	p=(int *)x;
	q=(int *)y;
	if(*p>*q)return 1;
	if(*p==*q)return 0;
	if(*p<*q)return -1;
}

int search_1(int dangqian,int mm)
{
	int i;
	if(FF)return 1;
	for(i=mm;i>-1;i--)
	{
		if(dangqian+a[i]>k||b[i]==1)continue;
		dangqian+=a[i];
		b[i]=1;
		if(dangqian==k)
		{
			FF=1;
			return 1;
		}
		search_1(dangqian,mm-1);
		if(FF)return 1;
		b[i]=0;
		dangqian-=a[i];
	}
	return 1;
}


int judge()
{
	int i,j,dangqian=0;
hehe:	for(i=0;i<n;i++)
		{
			FF=0;
			search_1(0,n-1);
			if(FF)break;
			else
				return 1;
		}
    	for(i=0;i<n;i++)
		{
	    	if(b[i]==0)
			{
		    	dangqian=0;
		    	goto hehe;
			}
			if(i==n-1){flag=1;return 1;}
		}
		return 1;
}


int main()
{
	int sum,i,j,temp=0;
	scanf("%d",&n);
	while(n)
	{
		for(i=0;i<max;i++)
		{
			a[i]=0;
			b[i]=0;
		}
		sum=0;flag=0;k=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		qsort((void *) a,n,sizeof(int),cmp);
		temp=a[n-1];
		for(k=temp;k<=sum;k++)
		{
			if(sum%k!=0)continue;
			for(j=0;j<max;j++)
				b[j]=0;
			judge();
			if(flag)
			{
				printf("%d\n",k);
				break;
				
			}
		}
		scanf("%d",&n);
	}
	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