WA#7 求好心人调试 token expected??
  • 板块CF377A Maze
  • 楼主SunsetVoice
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/1/14 21:21
  • 上次更新2023/10/24 04:13:30
查看原帖
WA#7 求好心人调试 token expected??
659460
SunsetVoice楼主2023/1/14 21:21

好神奇的错误提示:

神奇错误记录

code:

#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,k,b[101][101] = {0},bfsb[101][101] = {0};
char a[101][101] ;
bool check(int x,int y){
	return x>=0 and x<n and y>=0 and y<m and bfsb[x][y]==0 and a[x][y] == '.';
}
bool bfs_check(){
	int sx,sy;
	for(i = 0;i<n;i++){
		for(j = 0;j<m;j++){
			if(a[i][j]=='.'){
				sx = i;
				sy = j;
				break;
			}
		}
	}
	for(i = 0;i<n;i++){
		for(j = 0;j<m;j++){
			bfsb[i][j] = 0;
		}
	}
	queue<int>x;
	queue<int>y;
	x.push(sx);
	y.push(sy);
	while(x.empty()==false){
		if(check((x.front()+1),y.front())==true){
			x.push(x.front()+1);
			y.push(y.front()); 
			bfsb[x.front()+1][y.front()] = 1;
		}
		if(check(x.front(),y.front()+1)==true){
			x.push(x.front());
			y.push(y.front()+1); 
			bfsb[x.front()][y.front()+1] = 1;
		}
		if(check(x.front(),y.front()-1)==true){
			x.push(x.front());
			y.push(y.front()-1); 
			bfsb[x.front()][y.front()-1] = 1;
		}
		if(check(x.front()-1,y.front())==true){
			x.push(x.front()-1);
			y.push(y.front()); 
			bfsb[x.front()-1][y.front()] = 1;
		}
		x.pop();
		y.pop();
	}
	for(i = 0;i<n;i++){
		for(j = 0;j<m;j++){
			if(a[i][j]=='.' and bfsb[i][j]==0)return false;
		}
	}
	return true;
}
void dfs(int d){
	if(d==k and bfs_check()==true){
	//	cout<<"???"<<d<<" "<<k<<endl;
		for(i = 0;i<n;i++){
			for(j = 0;j<m;j++){
				cout<<a[i][j];
			}
			cout<<endl;
		}
	}else{
	//	cout<<"OK!Depth:"<<d<<endl;
		for(i = 0;i<n;i++){
			for(j = 0;j<m;j++){
				if(b[i][j]==0){
					a[i][j] = 'X';
					b[i][j] = 1;
//					for(int fi = 0;fi<n;fi++){
//						for(int fj = 0;fj<m;fj++){
//							cout<<a[fi][fj];
//						}
//						cout<<endl;
//					}
					dfs(d+1);
					a[i][j] = '.';
					b[i][j] = 0;
				}
			}
		}
	}
}
int main(){
	cin>>n>>m>>k;
	for(i = 0;i<n;i++){
		for(j = 0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='#')b[i][j] = 1;
			else b[i][j] = 0;
		}
	}
//	for(int fi = 0;fi<n;fi++){
//		for(int fj = 0;fj<m;fj++){
//			cout<<b[fi][fj];
//		}
//		cout<<endl;
//	}
	//cout<<k<<endl;
	dfs(0);
//	system ("pause");
	return 0;
}

2023/1/14 21:21
加载中...