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

为什么是WA啊,最后直接输出vis记录的数组不可以吗

Posted by 20152430227 at 2017-08-29 14:11:00 on Problem 3279
#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:
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