广搜求调
查看原帖
广搜求调
751450
Math_Miss楼主2024/10/25 13:46

求调
为啥输入有问题55555
就是实现n*n的迷宫确认有无出口awa

#include<bits/stdc++.h>
#define map adgsiofbduyfgvagfguydsghiu
using namespace std;
char map[101][101];
struct node{
	int x,y;
	int prepx;
	int prepy;
};
queue <node> q;
int n,m;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
bool book[101][101];
int startx,starty;
int endx,endy;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%s",&map[i]);
			if(map[i][j]=='P'){
				startx = i,starty = j;
			}
			if(map[i][j]=='@'){
				endx = i,endy = j;
			}
		}
	}
	
	node head,next;
	head.x = startx,head.y = starty;
	q.push(head);
	while(!q.empty()){
		head = q.front();
		q.pop();
		for(int i=0;i<=3;i++){
			next.x = head.x+dx[i];
			next.y = head.y+dy[i];
			if(book[next.x][next.y]){
				continue;
			}
			if(next.x<=0 || next.y<=0 || next.x>n ||next.y>n){
				continue;
			}
			if(next.x == endx||next.y == endy){
				cout<<"success";
				return 0;
			}
			book[next.x][next.y] = 1;
			q.push(next);
		}
	}
	
	return 0;
}
2024/10/25 13:46
加载中...