zoukankan      html  css  js  c++  java
  • (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接

    宽搜一下就行。

    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    using namespace std;
    int n,m;
    char str[209][209];
    int to[4][2]={1,0,-1,0,0,1,0,-1};
    bool mp[209][209];
    bool check(int x,int y)
    {
        if(x<0||x>=n||y<0||y>=m)return 1;
        if(str[x][y]=='#'||mp[x][y]==1)return 1;
        return 0;
    }
    int prx,pry;
    struct node
    {
        int x,y,time;
    };
    
    bool bfs(int posx,int posy)
    {
        int pt=-1,st=-1;
        queue<node>Q;
        node a,next;
        mp[posx][posy]=1;
        a.x=posx,a.y=posy,a.time=0;
        Q.push(a);
        while(!Q.empty())
        {
            a=Q.front();
            Q.pop();
            if(st==-1&&str[a.x][a.y]=='$') {
                st = a.time+1;
            }
            if(str[a.x][a.y]=='@'&&pt==-1) {
                pt = a.time+1;
            }
            if(pt!=-1&&st!=-1) {
                if(pt>=st) return 0;
                else return 1;
            }
            for(int i=0;i<4;i++)
            {
                next=a;
                next.x+=to[i][0];
                next.y+=to[i][1];
                if(check(next.x,next.y))continue;
                next.time=a.time+1;
                mp[next.x][next.y]=1;
                Q.push(next);
            }
        }
        if(pt!=-1)
            return 1;
        else return 0;
    }
    int main()
    {
       // freopen("cin.txt","r",stdin);
        while(~scanf("%d%d",&n,&m))
        {
            int posx,posy;
            memset(mp,0,sizeof(mp));
            for(int i=0;i<n;i++)
            {
                scanf("%s",str[i]);
                for(int j=0;j<m;j++)
                    if(str[i][j]=='%')
                {
                    posx=i;
                    posy=j;
                }
            }
            if(bfs(posx,posy))puts("Yes");
            else puts("No");
        }
        return 0;
    }
  • 相关阅读:
    【转载】高内聚低耦合
    【转载】locate命令的使用
    【转载】C内存对齐
    【原创】_INTSIZEOF 内存按照int对齐
    【转载】free查看内存
    Hive查询Join
    Hive数据查询
    Hive导入数据
    Hive表的修改Alter
    Hive中排序和聚集
  • 原文地址:https://www.cnblogs.com/Ritchie/p/6209310.html
Copyright © 2011-2022 走看看