zoukankan      html  css  js  c++  java
  • HDU 2102

    http://acm.hdu.edu.cn/showproblem.php?pid=2102

    中文题,开始以为要时间恰好,写个dfs超时,加个奇偶剪枝还超时,然后疯了

    问了sx,知道要小于等于那个时间就可以,当时吐血

    到了传送点必须传送

    有个trick是从'#'跳到'#'这种情况不能走

    #include <iostream>
    #include <queue>
    using namespace std ;
    typedef struct L{
        int x,y,f ;
        int step ;
    }L ;
    int n,m,t ;
    char map[2][11][11] ;
    int vis[2][11][11] ;
    int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}} ;
    int flag ;
    void bfs()
    {
        memset(vis,0,sizeof(vis)) ;
        flag=0 ;
        L now,next ;
        queue <L> q ;
        now.x=now.y=now.f=now.step=0 ;
        q.push(now) ;
        vis[0][0][0]=1 ;
        while(!q.empty())
        {
            now=q.front() ;
            if(map[now.f][now.x][now.y]=='P' && now.step<=t)
            {
                flag=1 ;
                return ;
            }
            if(map[now.f][now.x][now.y]=='P')
            {
                return ;
            }
            for(int i=0;i<4;i++)
            {
                next.x=now.x+dir[i][0] ;
                next.y=now.y+dir[i][1] ;
                next.f=now.f ;
                int xx=next.x ;
                int yy=next.y ;
                int ff=next.f ;
                if(xx<0 || xx>=n)
                    continue ;
                if(yy<0 || yy>=m)
                    continue ;
                if(map[ff][xx][yy]=='*')
                    continue ;
                if(map[ff][xx][yy]=='#' && map[ff^1][xx][yy]=='*')
                    continue ;
                if(map[ff][xx][yy]=='#' && map[ff^1][xx][yy]=='#')
                    continue ;    
                if(!vis[ff][xx][yy] && map[ff][xx][yy]=='#' && vis[ff^1][xx][yy]==0)
                {
                    vis[ff][xx][yy]=1 ;
                    next.f^=1 ;
                    vis[next.f][xx][yy]=1 ;
                    next.step=now.step+1 ;
                    q.push(next) ;
                }
                if(!vis[ff][xx][yy] && map[ff][xx][yy]!='#')
                {
                    vis[ff][xx][yy]=1 ;
                    next.step=now.step+1 ;
                    q.push(next) ;
                }
            }
            q.pop() ;
        }
    }
    int main()
    {
        int c ;
        scanf("%d",&c) ;
        while(c--)
        {
            scanf("%d%d%d%*c",&n,&m,&t) ;
            for(int i=0;i<2;i++)
            {
                for(int j=0;j<n;j++)
                    scanf("%s",map[i][j]) ;
                getchar() ;
            }
            bfs() ;
            if(flag)
                puts("YES") ;
            else
                puts("NO") ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    iOS AutoLayout的用法
    UIPickerView的使用(一)
    UIPickerView的使用(二)
    logging模块
    configparser模块
    hashlib模块
    json & pickle 模块
    对表的操作
    表记录曾删改查
    库、表曾删改查和存储引擎
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/3423757.html
Copyright © 2011-2022 走看看