设为首页 加入收藏

TOP

HDU 4528 BFS 小明系列故事――捉迷藏
2014-11-23 17:30:38 来源: 作者: 【 】 浏览:12
Tags:HDU 4528 BFS 小明 系列 故事 捉迷藏

原题直通车:HDU 4528 小明系列故事——捉迷藏

分析: 标记时加两种状态就行.


代码:


 
#include   
#include   
#include   
#include   
using namespace std;  
  
const int maxn=101;  
char f[maxn][maxn];  
int dx[]={0,0,-1,1};  
int dy[]={1,-1,0,0};  
bool vis[maxn][maxn][2][2];  
int n,m,k,ei,ej,di,dj,si,sj;  
struct node{  
    int x,y,time,p,q;  
}rt,ne;  
void work(node &rt){  
    bool u;  
    if(!rt.p&&rt.x==ei){  
        int a=min(rt.y,ej), b=max(rt.y,ej);  
        u=false;  
        for(int i=a+1;iM;  
    rt.x=si, rt.y=sj, rt.time=0, rt.p=0, rt.q=0;  
    vis[si][sj][0][0]=true;  
    M.push(rt);  
    while(!M.empty()){  
        rt=M.front(); M.pop();  
        work(rt);  
        if(rt.p&&rt.q) return rt.time;  
        for(int i=0;i<4;++i){  
            ne=rt; ne.x+=dx[i]; ne.y+=dy[i]; ne.time+=1;  
            if(ne.x<0||ne.x>=n||ne.y<0||ne.y>=m||ne.time>k||f[ne.x][ne.y]!='.') continue;  
            if(!vis[ne.x][ne.y][ne.p][ne.q]){  
                M.push(ne);  
                vis[ne.x][ne.y][ne.p][ne.q]=true;  
            }  
        }  
    }  
    return -1;  
}  
int main(){  
    int T,i,j,t,u,cas=1; scanf("%d",&T);  
    while(T--){  
        scanf("%d%d%d",&n,&m,&k);  
        for(i=0;i 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1251 Jungle Roads 下一篇HDU 4576 Robot (概率DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·请问c语言刚入门,该 (2025-12-26 10:21:04)
·python 编程怎么定义 (2025-12-26 10:21:01)
·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)