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
北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

那位大哥帮帮忙,这题总是WA,到底错哪了?

Posted by 20091000302 at 2009-10-23 11:30:53 on Problem 3279
# include<stdio.h>
# include<string.h>

int grid[19][19];
int n,m,f;
int ar[20],br[20][20];
void turn(int a)
{     
      int i=m;
	  memset(ar,0,sizeof(ar));
	  memset(br,0,sizeof(br));
	  while(a)
	  {
         ar[i]=a%2;
		 br[1][i]=a%2;
		 a=a/2;
		 i--;
	  }
}
int meiju()
{
	int i=m,j,k,t,x,y;int grids[20][20];
	f=1;
	while(i--)f=f<<1;
	memset(ar,0,sizeof(ar));
	memset(br,0,sizeof(br));
    for(i=0;i<f;i++)
	{
        turn(i);
        for(x=1;x<=n;x++)
		{
			for(y=1;y<=m;y++)
				grids[x][y]=grid[x][y];
		}
        for(j=1;j<=n;j++)
		{
		   for(k=1;k<=m;k++)
		   {  
			   grids[j][k]=grids[j][k]^ar[k];
			   if(ar[k])
			   {   
				   grids[j-1][k]=(grids[j-1][k]+1)%2;
				   grids[j][k-1]=(grids[j][k-1]+1)%2;
				   grids[j][k+1]=(grids[j][k+1]+1)%2;
				   grids[j+1][k]=(grids[j+1][k]+1)%2;
			   }
		   }
		   for(k=1;k<=m;k++)
		   { 
//			   if(i==5){printf("%d ",ar[k]);}
			   ar[k]=grids[j][k];
			   br[j+1][k]=ar[k];
		   }
//		   if(i==5)printf("\n");
		}
	
	   for(t=1;t<=m;t++)
	   { 
		  if(grids[n][t])break;
	   }
	   if(t>m)return 1;
	}
	return 0;
}
int main()
{
    int i,j,k;
	while(EOF!=scanf("%d%d",&n,&m))
	{
		for(i=1;i<=n;i++)
		{  
            for(j=1;j<=m;j++)
			scanf("%d",&grid[i][j]);
		}
		k=meiju();
		if(k==0)printf("IMPOSSIBLE\n");
		else 
		{  
			for(i=1;i<=n;i++)
			{
				for(j=1;j<=m;j++)
				{
                    printf("%d ",br[i][j]);
				}
				printf("\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