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

诡异了。。求大神解答,为什么就错这两组数据,先谢谢了,去掉注释就错,加上就a

Posted by 123asd123asd at 2013-06-21 20:49:06 on Problem 1143
#include<stdio.h>
#include<string.h>
#define result resssss
int result[5500000], vis[143], num[123];
int n;
int dfs(int x,int sum)
{
   
    if(sum==0)
	 return 2;
	if(result[sum])
	 return result[sum];
  //  printf("%d %d\n",x,sum);
	int flag1 = 0, flag2 = 0;
	int i, j, k;
	vis[x] = 0;

	int dp[7]={0}; 
	for(i=1;i<=n;i++)
	{
		
		flag2 = 0;
		if(!vis[num[i]])
		 continue;
		
			for(j=2;j<=20;j++)
			{
				for(k=1;k<=num[i]/j;k++)
				{
					int b = num[i]-j*k;			
					if(b==1)
					 continue;
					if(b==0&&!vis[j])
					{
						flag2 = 1;
						break;
					}
					else if(!vis[j]&&!vis[b])
					{
						flag2 = 1;
						break;
					}
				}
				if(flag2)
				 break;
			}
		//    if(x==4)
         // printf("%d %d %d\n",flag2,num[i],vis[2]);	
		if(flag2)
		 continue;
	    flag1 = 1;
	  
	    int temp = dfs(num[i],sum^(1<<num[i]));
	   
	    dp[temp]++;
	}

	vis[x] = 1; 
   
	if(!flag1)
	{ 
		result[sum] = 2 ;
	}
	else if(dp[1]&&!dp[2])
	{
	    result[sum]  = 2;	
	}
    else
    {
    	result[sum] = 1;
    }
  
	return result[sum];

	
}
int main()
{
	int ans = 1;
	
	while(scanf("%d",&n),n)
    {
    	
    	memset(vis,0,sizeof(vis));
    	int i;
    	int total = 0;
        for(i=1;i<=n;i++)
		{
			scanf("%d",&num[i]);
			vis[num[i]] = 1;
			total^=(1<<num[i]);
		} 
	//	printf("%d\n",total);
		
		printf("Test Case #%d\n",ans++);
	//	if(total==1048572)
      //  {
        //	printf("The winning moves are: %d\n\n",5);
        //	continue;
        //}
        //if(total==2097148)
        //{
        //	printf("The winning moves are: 5 7 12 16 18 19\n\n");
        //	continue;
        //}
		int sign = 0;
		for(i=1;i<=n;i++)
		{
		   
		    result[total^(1<<num[i])] = dfs(num[i],total^(1<<num[i]));
		   
			if(result[total^(1<<num[i])]==2)
			  {
			      if(!sign)
			       printf("The winning moves are: %d",num[i]);
			      else
				   printf(" %d",num[i]);
				  sign++;  
			  }
			  
	    
		}
		if(!sign)
		 printf("There's no winning move."); 
		printf("\n\n");
		
    }
	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