@[nothing__](/user/649246)
你的 `check()` 就写得有问题诶...
HACK:
```
5 5
OOOOO
OOOOO
XXXXX
XOOOO
XOOOO
1 1 5 5
0 0 0 0
```
应输出:
```
Poor Harry
```
by ilibilib @ 2023-11-29 14:28:57
@[ilibilib](/user/1039659) 谢谢
显然是我bfs最后忘记bk判断是否有解了
但是16分。哭
```
#include<bits/stdc++.h>
using namespace std;
const int N=16400;
string ss[N];
int n, m, sx, sy, ex, ey;
map<int, bool> mp[N];
struct node{int x, y, dep;} ;
int dx[4]={1, -1, 0, 0};
int dy[4]={0, 0, 1, -1};
int dxx[8]={1, 1, 1, -1, -1, -1, 0, 0};
int dyy[8]={1, -1, 0, 1, -1, 0, 1, -1};
bool pd(int x, int y) {
if(ss[x][y]=='X') return true;
else return false;
}
bool check() {
for(int i=0;i<8;i++) {
int xx=ex+dxx[i], yy=ey+dyy[i];
if(xx<0||yy<0||xx>=n||yy>=m) continue;
if(!pd(xx, yy)) return false;
}
return true;
}
void init() {
for(int i=1;i<=n;i++) mp[i].clear();
for(int i=0;i<8;i++) {
int xx=ex+dxx[i], yy=ey+dyy[i];
if(xx<0||yy<0||xx>=n||yy>=m) continue;
if(pd(xx, yy)) continue;
while(!pd(xx, yy)) {
if(!mp[xx][yy]) mp[xx][yy]=true;
xx=xx+dxx[i], yy=yy+dyy[i];
if(xx<0||yy<0||xx>=n||yy>=m) break;
}
}
}
void bfs() {
bool bk=false; int ans=0;
map<int, bool> ct[N];
queue<node> q; q.push({sx, sy, 0});
if(mp[sx][sy]) {puts("0"); return ;}
while(!q.empty()) {
node x=q.front(); q.pop();
for(int i=0;i<4;i++) {
int xx=x.x+dx[i], yy=x.y+dy[i];
if(xx<0||yy<0||xx>=n||yy>=m) continue;
if(pd(xx, yy)) continue;
if(ct[xx][yy]) continue;
else ct[xx][yy]=true;
if(mp[xx][yy]) {bk=true, ans=x.dep; break;}
else mp[xx].erase(yy);
q.push({xx, yy, x.dep+1});
}
if(bk) break;
}
if(bk==true) printf("%d\n", ans+1);
else puts("Poor Harry");
}
int main() {
scanf("%d%d", &n, &m);
for(int i=0;i<n;i++) cin >> ss[i];
while(scanf("%d%d%d%d", &sx, &sy, &ex, &ey)!=EOF) {
if(sx+sy+ex+ey==0) break;
--sx, --sy, --ex, --ey;
if(check()) {puts("Poor Harry"); continue;}
init();
bfs();
}
return 0;
}
```
by nothing__ @ 2023-12-01 13:03:23
下不了数据就很难受,也不想对拍。
by nothing__ @ 2023-12-01 13:05:23
找到一个bug,mp[i]应该从0开始清空
但是36分
by nothing__ @ 2023-12-01 13:20:49
此帖结。
看错了,先输入了起点,后输入了终点。哭。
by nothing__ @ 2023-12-01 13:28:56