题目大意:
从起点走到终点,走到点的话,点会变成X,如果走到了X的话,就会掉下去。如果掉下去的点是终点,那么输出YES,否则输出NO。
思路:因为点的状态会有变化,所以最开始以为广搜要有伴随结构体走的图,没敢敲BFS,敲的DFS,果断TLE。。。。。。其实仔细想想完全不需要伴随结构体走的map,如果有走到点的地方让他能变成X,那么无非必要讨论其他到这里会不会有点变叉的问题,还是欠缺了思考。
AC代码:
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
struct zuobiao
{
int x,y;
}now,nex;
int sx,sy,ex,ey;
char a[505][505];
int fx[4]={0,0,-1,1};
int fy[4]={1,-1,0,0};
int n,m;
int ok;
void bfs(int x,int y)
{
now.x=x;
now.y=y;
queue<zuobiao >s;
s.push(now);
while(!s.empty())
{
now=s.front();
s.pop();
for(int i=0;i<4;i++)
{
nex.x=fx[i]+now.x;
nex.y=fy[i]+now.y;
if(nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<m)
{
if(a[nex.x][nex.y]=='X')
{
if(nex.x==ex&&nex.y==ey)
{
printf("YES\n");
return ;
}
}
else
{
a[nex.x][nex.y]='X';
s.push(nex);
}
}
}
}
printf("NO\n");
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++)
{
scanf("%s",a[i]);
}
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
sx--;sy--;ex--;ey--;
ok=0;
bfs(sx,sy);
}
}