hdu1728

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n, m, flag;
int k, x1, x2, y1, y2;
char s[105][105];
int dist[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};

struct node{
    int x, y, w;
    bool operator <(const node &a) const {
        return w > a.w;
    }
};

void bfs(){
    int vis[105][105];
    memset(vis, 0, sizeof(vis));
    priority_queue<node> q;
    q.push(node{x1, y1, -1});
    while(q.size()){
        node t = q.top();
        q.pop();
        //if(t.x == x2 && t.y == y2){
        //    if(t.w <= k){
        //        printf("yes\n");
            //    flag = 1;
            //}
        //    return ;
        //}
        for (int i = 0; i < 4; i++){
            int x = t.x + dist[i][0], y = t.y + dist[i][1];
            while(!(x < 1 || x > n || y < 1 || y > m || s[x][y] == '*')){
                if(!vis[x][y] || vis[x][y] > t.w + 1){
                    vis[x][y] = t.w + 1;
                    q.push(node{x, y, t.w + 1});
                    if(x == x2 && y == y2 && t.w + 1 <= k){
                        printf("yes\n");
                        flag = 1;
                        return ;
                    }
                }
                x += dist[i][0], y += dist[i][1];
            }
            
        }
    }
}

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        scanf("%d %d", &n, &m);
        for (int i = 1; i <= n; i++){
            scanf("%s", s[i] + 1);
        }
        scanf("%d %d %d %d %d",&k, &y1, &x1, &y2, &x2);
        if(s[x2][y2] == '*'){
            printf("no\n");
            continue;
        }
        flag = 0;
        bfs();
        if(!flag){
            printf("no\n");
        }
    }
    return 0;
}
/**/

注意行和列反过来!!多坑啊

全部评论

相关推荐

10-29 16:42
门头沟学院 Java
1.今天什么国标的公司打电话约面试,还得准备ppt,好麻烦,网上查薪资一般,打算拒了,不面了2.字节又复活了,什么安全开发,也不知道怎么样,面一面试试吧,还是挺想去字节的,但好难,随缘吧所以今天没面试
嵌入式的小白:面试前可以好好准备下 1.看看你投递的岗位的岗位描述,分析下是哪个业务线,同使要罗列他们描述中提到的技术点 2.根据1中的两点准备 3.岗位描述中应该还有语言要求,这个刷刷八股,要是对自己语言能力很有把握,那就不用看这点了 4.找下你简历中项目部分,看有没有和岗位描述中技术点重合的,这种在面试提到项目时,是高概率问题 好好准备,祝你面试顺利
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务