http://codeforces.com/problemset/problem/540/C
简单bfs,注意结束条件。
#include
#include
#include
using namespace std;
string a[];
int endx,endy,n,m,dir[][] = {-,,,-,,,,};
struct point{
int x,y;
}start;
int main()
{
cin >> n >> m;
for(int i = ;i < n;i++) cin >> a[i];
cin >> start.x >> start.y >> endx >> endy;
start.x--;
start.y--;
endx--;
endy--;
queue
q.push(start);
while(!q.empty())
{
point now = q.front();
q.pop();
for(int i = ;i < ;i++)
{
int xx = now.x+dir\[i\]\[\];
int yy = now.y+dir\[i\]\[\];
if(xx == endx && yy == endy && a\[xx\]\[yy\] == 'X')
{
printf("YES\\n");
return ;
}
if(xx < || xx >= n || yy < || yy >= m) continue;
if(a\[xx\]\[yy\] == 'X') continue;
point temp;
temp.x = xx;
temp.y = yy;
q.push(temp);
a\[xx\]\[yy\] = 'X';
}
}
printf("NO\\n");
return ;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章