#include <iostream>
#include <queue>
using namespace std;
int n,m,s2,e2;
int b[205][205],d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char a[205][205];
struct point{
int x,y,step;
}p;
queue <point> q;
int bfs(point pp)
{
int i,j,k;
point t;
q.push(pp);
while(!q.empty())
{
p=q.front(),q.pop();
for(i=0;i<4;i++)
{
j=p.x+d[i][0]; k=p.y+d[i][1];
if(j>=0&&j<n&&k>=0&&k<m&&a[j][k]!='#')
{
t.x=j; t.y=k; t.step=p.step+1;
if(a[j][k]=='x') t.step++;
if(t.step<b[j][k]) q.push(t), b[j][k]=t.step;
}
}
}
return b[s2][e2];
}
int main(int argc, char *argv[])
{
int i,j,k;
while(cin>>n>>m)
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
cin>>a[i][j]; b[i][j]=1000000;
if(a[i][j]=='a') p.x=i,p.y=j;
if(a[i][j]=='r') s2=i,e2=j;
}
p.step=0; b[p.x][p.y]=0;
k=bfs(p);
if(k==1000000)
cout<<"Poor ANGEL has to stay in the prison all his life."<<endl;
else cout<<k<<endl;
}
return 0;
}

zoj 1649的更多相关文章

  1. BFS zoj 1649

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 //hnldyhy(303882171) 11:12:46 // z ...

  2. HDU 1242 Rescue(BFS),ZOJ 1649

    题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...

  3. zoj 1649 Rescue (BFS)(转载)

    又是类似骑士拯救公主,不过这个是朋友拯救天使的故事... 不同的是,天使有多个朋友,而骑士一般单枪匹马比较帅~ 求到达天使的最短时间,杀死一个护卫1 units time , 走一个格子 1 unit ...

  4. ZOJ 1649:Rescue(BFS)

    Rescue Time Limit: 2 Seconds      Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...

  5. zoj 1649 Rescue

    BFS..第一次使用C++ STL的队列来写广搜. #include<stdio.h> #include<string.h> #include<math.h> #i ...

  6. zoj 1649 bfs

    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...

  7. ZOJ 1649 Rescue(有敌人迷宫BFS)

    题意 求迷宫中从a的位置到r的位置须要的最少时间  经过'.'方格须要1s  经过'x'方格须要两秒  '#'表示墙 因为有1s和2s两种情况  须要在基础迷宫bfs上加些推断 令到达每一个点的时间初 ...

  8. HZNU Training 1 for Zhejiang Provincial Collegiate Programming Contest

    赛后总结: TJ:今天我先到实验室,开始看题,一眼就看了一道防AK的题目,还居然觉得自己能做wwww.然后金姐和彭彭来了以后,我和他们讲了点题目.然后金姐开始搞dfs,我和彭彭看榜研究F题.想了很久脑 ...

  9. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

随机推荐

  1. Spring Boot 多模块项目创建与配置 (一)

    最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都使用spring boot框架.之前有零零散散学过一些 ...

  2. lucene入门查询索引——(三)

    1.用户接口(lucene不提供)

  3. 使用badblocks命令检测、修复硬盘坏道(待验证)

    今天我的新硬盘到了.暂时没想好怎么用它.可以把它装入光驱位硬盘架给G430用,也可以把它当成移动硬盘来用. 想起以前记录过一个badblocks的用法,用来检查坏道,这里再贴一遍备用. ####### ...

  4. gentoo系统安装

    1. Gentoo常用镜像   ===>http://www.linuxsir.org/bbs/thread263600.html 2. 安装方式1 http://www.linuxidc.co ...

  5. laravel 批量更新

    /** * 转发动态和资讯数量统计 */ public function forwardCounts(FeedModel $feedModel) { //统计动态转发的id $feeds=$feedM ...

  6. java判断部署项目使用的服务器类型

    有两种方式 1.项目引入portal-kernel.jar.项目运行时使用 根据返回boolean值判断类型! 2.自己写java类 package webService.ZFGX.service; ...

  7. CEF 中的那些坑

    CEF (Chromium Embedded Framework) 的大名也听说很久了,最近因为客户的需求,简单地研究了一下.结果遇到了一个接一个的坑,且慢慢道来.比之前用QtWebkit的坑还要多和 ...

  8. Angular 2的表格控件

    Angular 2的表格控件 前端框架一直这最近几年特别火的一个话题,尤其是Angular 2拥有众多的粉丝.在2016年9月份Angular 2正式发布之后,大量的粉丝的开始投入到了Angular ...

  9. 【AtCoder】AGC029(A-E)

    A - Irreversible operation 题解 把每个B后面的W个数累加起来即可 代码 #include <bits/stdc++.h> #define fi first #d ...

  10. django 2.0 中URL的include方法使用分析

    一.问题出现: 在使用Django2.0,配置全局URL时,希望指向某个APP的URL,配置如下: from django.contrib import admin from django.conf. ...