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

Help!!!!为什么总是WA?是算法有问题吗,请帮忙看看,谢谢.......

Posted by me at 2005-04-16 17:09:37 on Problem 1011
#include<stdio.h>

main()
{
	int a[100],n,max,b[10000],m,i,j,a1[100],total,k,l,temp;
	scanf("%d",&n);
	while(n>0)
	{
		total=0;max=0;

		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			total+=a[i];
			max=max>a[i]?max:a[i];
		}

		for(i=1;i<n;i++)
			for(j=i+1;j<=n;j++)
				if(a[i]<a[j]){temp=a[i];a[i]=a[j];a[j]=temp;}

		m=0;
		for(i=max;i<=total;i++)if(total%i==0)b[++m]=i;

		for(i=1;i<=m;i++)
		{
			k=total/b[i];
			for(j=1;j<=n;j++)a1[j]=a[j];
			while(k>0)
			{
				l=b[i];
				for(j=1;j<=n;j++)
					if(l==0)break;
					else if((a1[j]<=l)&&(a1[j]!=0)){l=l-a1[j];a1[j]=0;}
				if(l!=0)break;
				else k--;
			}
			if(k==0)break;
		}

		printf("%d\n",b[i]);
		scanf("%d",&n);
	}
}

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