标签:
2 5 5 ...** *.**. ..... ..... *.... 1 1 1 1 3 5 5 ...** *.**. ..... ..... *.... 2 1 1 1 3
no yes
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #define maxn 200 using namespace std; char map[maxn][maxn]; int turn[maxn][maxn]; int n, m, k, sx, sy, ex, ey; bool flag; int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0}; struct node{ int x, y; }; bool check(int x, int y){ if(x >= 0 && x < n && y >=0 && y < m && map[x][y] != '*') return true; else return false; } void bfs(int sx, int sy){ queue<node>q; node st, ed; st.x = sx, st.y = sy; q.push(st); while(!q.empty()){ st = q.front(); q.pop(); if(st.x == ex && st.y == ey){ if(turn[st.x][st.y] - 1 <= k){ flag = true; return ; } } for(int i = 0; i < 4; ++i){ ed.x = st.x + dir[i][0]; ed.y = st.y + dir[i][1]; while(check(ed.x ,ed.y)){ //q.push(ed); if(turn[ed.x][ed.y] == 0){ turn[ed.x][ed.y] = turn[st.x][st.y] + 1; q.push(ed); } ed.x += dir[i][0];//沿着四个走到底。 ed.y += dir[i][1]; } } } } int main (){ int T; scanf("%d", &T); while(T--){ scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) scanf("%s", map[i]); scanf("%d%d%d%d%d", &k, &sy, &sx, &ey, &ex); sx--, sy--, ex--, ey--; flag = 0; memset(turn, 0, sizeof(turn)); bfs(sx, sy); if(flag) printf("yes\n"); else printf("no\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/hpuhjh/article/details/47310941