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 |
哪位大神帮忙看看呗 实在不知道哪里错了#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> using namespace std; int map[16][16]; int m,n; int vis[16][16]; void exchange(int i,int j){//0变1,1变0 即与1异或 map[i][j] ^= 1; if(i-1>=0) map[i-1][j] ^=1; if(i+1<m) map[i+1][j] ^=1; if(j-1>=0) map[i][j-1] ^=1; if(j+1<n) map[i][j+1] ^=1; } bool bfs(){ for(int i=0;i<m-1;i++){ for(int j=0;j<n;j++){ if(map[i][j]==1){ exchange(i+1,j); vis[i+1][j]=1; } } } for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(map[i][j]==1) return false; } } return true; } int main(){ while(scanf("%d%d",&m,&n)!=EOF){ getchar(); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ scanf("%d",&map[i][j]); } } memset(vis,0,sizeof(vis));//刚开始,将vis全部置0 if(bfs()){ for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cout<<vis[i][j]<<' '; } cout<<endl; } } else cout<<"IMPOSSIBLE"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator