Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
那位大哥帮帮忙,这题总是WA,到底错哪了?# 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator