首页 > 代码库 > Codeforces_540_C
Codeforces_540_C
http://codeforces.com/problemset/problem/540/C
简单bfs,注意结束条件。
#include<iostream>#include<cstdio>#include<queue>using namespace std;string a[505];int endx,endy,n,m,dir[][2] = {-1,0,0,-1,1,0,0,1};struct point{ int x,y;}start;int main(){ cin >> n >> m; for(int i = 0;i < n;i++) cin >> a[i]; cin >> start.x >> start.y >> endx >> endy; start.x--; start.y--; endx--; endy--; queue<point> q; q.push(start); while(!q.empty()) { point now = q.front(); q.pop(); for(int i = 0;i < 4;i++) { int xx = now.x+dir[i][0]; int yy = now.y+dir[i][1]; if(xx == endx && yy == endy && a[xx][yy] == ‘X‘) { printf("YES\n"); return 0; } if(xx < 0 || xx >= n || yy < 0 || 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 0;}
Codeforces_540_C
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。