Codeforces_540_C
阅读原文时间:2023年07月10日阅读:1

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;
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 ;  

}