zoukankan      html  css  js  c++  java
  • 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
    ");
                    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
    ");
        return 0;
    }
  • 相关阅读:
    加载器学习记录
    日常记录
    php实现银联支付
    PHP 判断密码强度
    laravel artisan 命令列表
    PHP && ,and ,||,or 的区别
    数组与对象的转换
    正则表达式
    微信退款
    laravel when 的用法
  • 原文地址:https://www.cnblogs.com/zhurb/p/5874929.html
Copyright © 2011-2022 走看看