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

疯了,好不容易在编译器上通过,结果TLE了! 求救!!!(附源代码C)

Posted by Sunjing at 2010-01-07 23:32:41 on Problem 1014
#include <stdio.h>
int Sun(int a[][7],int); 
int main()
{
	int a[100][7];
	int *p;
	int i,k=0;
	for(i=0;;i++){ /*输入各种情况*/ 
		scanf("%d%d%d%d%d%d",&a[i][1],&a[i][2],&a[i][3],
							&a[i][4],&a[i][5],&a[i][6]);
		if(a[i][1]||a[i][2]||a[i][3]||a[i][4]||a[i][5]||a[i][6]) /*判断是否为0 0 0 0 0 0*/ 
			k++;
		else
			break;
	}
	for(i=0;i<k;i++){
		printf("Collection #%d:\n",i+1);
		printf("%s",Sun(a,i)?"Can be divided.\n\n":"Can't be divided.\n\n");
	}
	return 0;
}
int Sun(int a[][7],int i)	/*判断数组a[i][7]是否满足dividing*/ 
{
	int values,n1,n2,n3,n4,n5,n6;
	values=1*a[i][1]+2*a[i][2]+3*a[i][3]+4*a[i][4]+5*a[i][5]+6*a[i][6];
	if(values%2) /*如果总values是奇数,则不可dividing*/ 
		return 0;
	else{		/*如果是偶数*/ 
		for(n1=0;n1<=a[i][1];n1++)  
			for(n2=0;n2<=a[i][2];n2++)
				for(n3=0;n3<=a[i][3];n3++)
					for(n4=0;n4<=a[i][4];n4++)
						for(n5=0;n5<=a[i][5];n5++)
							for(n6=0;n6<=a[i][6];n6++){
								if(n1*1+n2*2+n3*3+n4*4+n5*5+n6*6==values/2)	/*判断是否能dividing*/ 
									goto x;
								
								else
									;
									
							}
		return 0;
	   x:
	   	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