Math_Miss @ 2024-10-25 13:46:38
求调\ 为啥输入有问题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;
}
by zap2727 @ 2024-10-25 14:22:30
1.数组的map
和#define
的map
重名了。
2.#define
语句最好改为 #define map "adgsiofbduyfgvagfguydsghiu"
。
3.输入部分最好用cin
。
4.广搜部分没问题。
by zap2727 @ 2024-10-25 14:24:34
(题目板块:危)
@Math_Miss