zoukankan      html  css  js  c++  java
  • 【codevs1215】迷宫

    problem

    solution

    codes

    #include<iostream>
    #include<queue>
    using namespace std;
    struct xyz{
        int x, y;
        xyz(int x = 0, int y = 0):x(x),y(y){};
    };
    int m, n, book[20][20];
    char a[20][20];
    const int dx[] = {0,1,-1,0};
    const int dy[] = {1,0,0,-1};
    int main(){
        cin>>m;
        while(m--){
            cin>>n;
            for(int i = 0; i < n; i++)cin>>a[i];
            bool ok = false;
            queue<xyz>q;  q.push(xyz(0,0));
            while(!q.empty()){
                xyz t = q.front();  q.pop();
                book[t.x][t.y] = 1;
                if(t.x==n-1 && t.y==n-1){ ok = true; break;}
                for(int i = 0; i < 4; i++){
                    int newx = t.x+dx[i], newy = t.y+dy[i];
                    if(newx>=0 && newx<n && newy>=0 && newy<n && (a[newx][newy]=='.'||a[newx][newy]=='e') && !book[newx][newy])
                        { book[newx][newy] = 1; q.push(xyz(newx, newy)); }
                }
            }
            if(ok)cout<<"YES
    ";else cout<<"NO
    ";
        }
        return 0;
    }
  • 相关阅读:
    BGP
    ospf路由认证
    rip路由认证
    php-数组的相关函数及排序算法
    php-多维数组,数组遍历
    php-数组的概念,语法及特点
    php-错误处理
    MySQL性能优化
    JUC多线程03
    JUC多线程01
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444708.html
Copyright © 2011-2022 走看看