这里有个$dmbl$ AC,但这里80分WA的解法:
```
#include <bits/stdc++.h>
using namespace std;
struct point{
int x,y,step;
};
point q[10000000],s;
int front,tail,dx[]={1,-1,0,0},dy[]={0,0,1,-1},n,m,ex,ey;
int used[1001][1001];
char g[1001][1001];
int _map[1001][1001];
void init(){
memset(_map,0,sizeof(_map));
int gx[]={1,-1,0,0,1,-1,1,-1};
int gy[]={0,0,1,-1,1,1,-1,-1};
int x,y;
for(int i=0; i<8; i++){
//cout<<"Run for i="<<i<<endl;
x=ex,y=ey;
while(g[x][y]!='X'){
_map[x][y]=1;
x+=gx[i],y+=gy[i];
if(x>=n || y>=m || x<0 || y<0) break;
}
}
/*
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cout<<_map[i][j]<<' ';
}
cout<<endl;
}*/
}
void bfs(){
memset(used,0,sizeof(used));
front=tail=1;
if(_map[s.x][s.y]==1){
printf("0\n");
return;
}
q[1]=s;
used[s.x][s.y]=1;
while(front<=tail){
point u=q[front++];
point v;
for(int i=0; i<4; i++){
v.x=u.x+dx[i],v.y=u.y+dy[i],v.step=u.step+1;
if(v.x<0 || v.x>=n || v.y<0 || v.y>=n) continue;
if(used[v.x][v.y]==1) continue;
if(g[v.x][v.y]=='X') continue;
if(_map[v.x][v.y]==1){
printf("%d\n",v.step);
return ;
}
q[++tail]=v;
used[v.x][v.y]=1;
}
}
printf("Poor Harry\n");
}
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++){
scanf("%s",g[i]);
}
//printf("Finish to read.\n");
while(1){
int sx,sy;
scanf("%d %d %d %d",&ex,&ey,&sx,&sy);
if(ex==0 && ey==0 && sx==0 && sy==0) break;
s.x=sx-1,s.y=sy-1,s.step=0,ex-=1,ey-=1;
//printf("Begin to search.\n");
init();
bfs();
}
return 0;
}
```
by Moeebius @ 2021-09-07 20:50:02
@[thomaswmy](/user/531319) 可能是数组越界吧,开成vector应该就好了
by 林聪 @ 2021-09-07 20:51:21
@[Xiaohuba](/user/356003) dmbl是什么东西
by 林聪 @ 2021-09-07 20:52:57
但是错的三个点都是wa……
by thomaswmy @ 2021-09-08 18:32:51
而且题解里有人试过了,1600就能过
by thomaswmy @ 2021-09-08 18:41:00
找到错了
```cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int dx[]={0,0,1,-1,1,1,-1,-1};
const int dy[]={1,-1,0,0,1,-1,1,-1};
struct point{
int x,y,step;
};
point q[1000000],s,e;
int n,m;
char c,tmp[10];
int front,tail;
int x,y;
bool flag,end[3000][3000],maze[3000][3000],used[3000][3000];
int main() {
scanf("%d%d",&n,&m);
gets(tmp);
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
scanf("%c",&c);
if(c=='O') maze[i][j]=1;
else maze[i][j]=0;
}
gets(tmp);
}
while(true) {
scanf("%d%d%d%d",&e.x,&e.y,&s.x,&s.y);
if(s.x==0 && s.y==0 && e.x==0 && e.y==0) break;
if(s.x==e.x && s.y==e.y) {
printf("0\n");
continue;
}
memset(used,0,sizeof(used));
memset(end,0,sizeof(end));
s.step=0;
for(int i=0;i<8;i++) {
x=e.x,y=e.y;
while(maze[x][y]==1 && x>=1 && x<=n && y>=1 && y<=m) {
end[x][y]=1;
x+=dx[i],y+=dy[i];
}
}
if(end[s.x][s.y]==1) {
printf("0\n");
continue;
}
front=tail=1;
q[1]=s;
flag=0;
while(front<=tail) {
point u=q[front++];
point v;
for(int i=0;i<4;i++) {
v.x=u.x+dx[i];
v.y=u.y+dy[i];
v.step=u.step+1;
if(v.x<1 || v.x>n || v.y<1 || v.y>m) continue;
if(maze[v.x][v.y]==0) continue;
if(used[v.x][v.y]==1) continue;
if(end[v.x][v.y]==1) {
flag=1;
front=tail+1;
printf("%d\n",v.step);
break;
}
used[v.x][v.y]=1;
q[++tail]=v;
}
}
if(flag==0) {
printf("Poor Harry\n");
}
}
return 0;
}
```
忘加了一个换行
by thomaswmy @ 2021-09-09 21:53:59
或者用这样
```cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int dx[]={0,0,1,-1,1,1,-1,-1};
const int dy[]={1,-1,0,0,1,-1,1,-1};
struct point{
int x,y,step;
};
point q[1000000],s,e;
int n,m;
char c,tmp[10];
int front,tail;
int x,y;
bool end[3000][3000],maze[3000][3000],used[3000][3000];
void bfs() {
front=tail=1;
q[1]=s;
while(front<=tail) {
point u=q[front++];
point v;
for(int i=0;i<4;i++) {
v.x=u.x+dx[i];
v.y=u.y+dy[i];
v.step=u.step+1;
if(v.x<1 || v.x>n || v.y<1 || v.y>m) continue;
if(maze[v.x][v.y]==0) continue;
if(used[v.x][v.y]==1) continue;
if(end[v.x][v.y]==1) {
printf("%d\n",v.step);
return ;
}
used[v.x][v.y]=1;
q[++tail]=v;
}
}
printf("Poor Harry\n");
}
int main() {
scanf("%d%d",&n,&m);
gets(tmp);
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
scanf("%c",&c);
if(c=='O') maze[i][j]=1;
else maze[i][j]=0;
}
gets(tmp);
}
while(true) {
scanf("%d%d%d%d",&e.x,&e.y,&s.x,&s.y);
if(s.x==0 && s.y==0 && e.x==0 && e.y==0) break;
memset(used,0,sizeof(used));
memset(end,0,sizeof(end));
s.step=0;
for(int i=0;i<8;i++) {
x=e.x,y=e.y;
while(maze[x][y]==1 && x>=1 && x<=n && y>=1 && y<=m) {
end[x][y]=1;
x+=dx[i],y+=dy[i];
}
}
if(end[s.x][s.y]==1) {
printf("0\n");
continue;
}
bfs();
}
return 0;
}
```
by thomaswmy @ 2021-09-09 21:54:35