DFS chess problem

 

 

#include <cstdio> 
the using namespace STD; 
char Maze [15] [15]; // to store the size of the board 
bool vis [15] [15] ; // determines whether the current point is stored through 
int n, m; / / checkerboard rows and columns 
bool f; // identifier 
int dir [8] [2] = {{- 2, -1}, {- 1, -2}, {1, -2}, {1,2} , {2,1}, {1,2}, {- 1,2}, {- 2,1}}; // eight horses can walk direction 
BOOL in (int X, Y int) { 
	return X> = 0 && X <n-&& Y> = 0 && Y <m; 
} 
// in function used to determine whether the bounds 
void DFS (int X, int Y) { 
	iF (F) { 
		return; 
	} // process has found directly returns, reduce certain overhead 
	IF (Maze [X] [Y] == 'T') { 
		F = to true; 
		return; 
	} // find T return, referred to as identification to true 
	IF (in (X, Y) && Maze [X] [Y !] = '*' && VIS [X] [Y]) {! 
		VIS [X] [Y] = to true; // current point can go, talk referred to as VIS traveled 
		for (int i = 0; i <8 ;i ++) { 
			dfs (x + said [i] [0] + and say [i] [1]);++ I) { 
		} 
		// direction. 8 to exhaustive enumeration
		vis[x][y]=false;
		//取消标识 
	}
} 
int main(){
	int x,y; //用来记录起点的坐标 
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%c",&maze[i][j]);
		}
	}//输入棋盘 
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(maze[i][j]=='S'){
				x=i;
				y=j;
			}
		}
	}
	dfs(x,y);
	if(f){
		printf("YES!\n");
	}else{
		printf("No!\n");
	} 
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/jcahsy/p/12455207.html