Rescue(简单搜索题)

一看就知道和1026是一样的,并且比1026更简单!除了延迟处理,不含任何技巧!和我一样水平的银,赶紧练练手吧。。。TT。。http://acm.hdu.edu.cn/showproblem.php?pid=1242

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#define N 201
using namespace std;
int n,m,res,s,e;
int jump[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char map[N][N];
bool f[N][N];
struct node
{
    int x,y,s;
}q,r,p;
void init()
{
    int i,j;
    res=-1;
    for(i=0;i<n;i++)
    {
        getchar();
        for(j=0;j<m;j++)
        {
            cin>>map[i][j];
            if(map[i][j]=='r')
            {
                s=i;e=j;
            }
        }
    }
    memset(f,0,sizeof(f));
    /*for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        cout<<map[i][j];
        cout<<endl;
    }*/
}
int is_b(node p)
{
    if(p.x<0 || p.y<0 || p.x>=n || p.y>=m
    || f[p.x][p.y] || map[p.x][p.y]=='#')
    return 1;
    return 0;
}
void bfs()
{
    queue< node > que;
    q.x=s;q.y=e;q.s=0;
    f[s][e]=1;
    que.push(q);
    while(!que.empty())
    {
        q=que.front();que.pop();
        if(map[q.x][q.y]=='a')
        {
            res=q.s;
            return;
        }
        if(map[q.x][q.y]=='x')
        {
            ++q.s;
            map[q.x][q.y]='.';
            que.push(q);
        }
        else
        {
            for(int i=0;i<4;i++)
            {
                p.x=q.x+jump[i][0];
                p.y=q.y+jump[i][1];
                p.s=q.s+1;
                if(is_b(p)) continue;
                f[p.x][p.y]=1;
                que.push(p);
            }
        }
    }
}
int main ()
{
    //freopen("j.txt","r",stdin);
    while(cin>>n>>m)
    {
        init();
        bfs();
        if(res!=-1) cout<<res<<endl;
        else cout<<"Poor ANGEL has to stay in the prison all his life."<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值