- 迷宫
P2499 迷宫
- 2025-3-30 16:58:16 @
#include<iostream>
using namespace std;
char mp[105][105];
int n,oo;
int ha,la,hb,lb;
bool v[105][105];
int dir[4][2]= { {-1,0},{1,0},{0,-1},{0,1} };
bool dfs(int x,int y) {
if(x == hb && y == lb) {
return 1;
}
for(int i=0; i<4; i++) {
int tx = x+dir[i][0];
int ty = y+dir[i][1];
if(0<=tx&&tx<n&&0<=ty&&ty<n && mp[tx][ty] != '#' && !v[tx][ty]) {
v[tx][ty] = 1;
if(dfs(tx,ty)) {
return 1;
}
}
}
return 0;
}
int main() {
int sx,sy;
cin>>oo;
for(int l=0; l<oo; l++) {
cin>>n;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
cin>>mp[i][j];
}
}
cin>>ha>>la>>hb>>lb;
sx = ha;
sy = la;
bool v[105][105];
if(dfs(sx,sy) && mp[ha][la] != '#' && mp[hb][lb] != '#') {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
}
return 0;
}
为什么是错的
0 comments
No comments so far...
Information
- ID
- 2499
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- # Submissions
- 122
- Accepted
- 13
- Uploaded By