#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. [转]GCC系列: __attribute__((visibility("")))

    在 objc-api.h 里面有很多关于__attribute__ 的定义. 例如 #if !defined(OBJC_VISIBLE) # if TARGET_OS_WIN32 # if defin ...

  2. mysql_存储过程_后一行减去前一行

    DELIMITER $$ /*统计单个用户登录次数的存过 @times_count int 返回值 @i 记录行号的变量 初始值为0 @temp 记录时间差的变量 @total 记录登录次数的变量 初 ...

  3. mysql学习------错误日志和通用查询日志

    一.启动错误日志 1.在不同情况下,错误日志会记录在不同的位置.如果没有在配置文件中指定文件名,则文件名默认为hostname.err 2.在mysql5.6的rpm发布方式中,错误的日志默认的放置在 ...

  4. casperjs 知乎登陆

    phantom.casperTest = true; phantom.outputEncoding="utf-8"; var fs = require('fs'); var cas ...

  5. K-means聚类算法的三种改进(K-means++,ISODATA,Kernel K-means)介绍与对比

      一.概述 在本篇文章中将对四种聚类算法(K-means,K-means++,ISODATA和Kernel K-means)进行详细介绍,并利用数据集来真实地反映这四种算法之间的区别. 首先需要明确 ...

  6. C++ Primer读书笔记(3)

    vector: 本科时学C++的时候没学过vector,正好补一下. 第一个要注意的地方是要正确区分列表初始值还是元素数量. 第二点是不能使用范围for向vector对象添加元素,范围for语句体内不 ...

  7. Linux学习笔记:sed删除、插入数据

    一.sed删除文件第一行 sed -i '1d' file.txt -- 删除第一行 sed -i 'nd' file.txt -- 删除第n行 sed -i '$d' file.txt -- 删除最 ...

  8. [转] Web移动端Fixed布局的解决方案

    移动端业务开发,iOS 下经常会有 fixed 元素和输入框(input 元素)同时存在的情况. 但是 fixed 元素在有软键盘唤起的情况下,会出现许多莫名其妙的问题. 这篇文章里就提供一个简单的有 ...

  9. HDU4267 树状数组

    题意描述: 给定一个数组,有两种操作: 操作一:a b k c 对于区间a~b之间的元素如果下标满足(i-a)%k=0则给元素i加上c 操作二:a          查询下标为a的元素当前值 解题思路 ...

  10. 001 SpringMVC的helloWorld程序

    一:helloworld程序 1.结构目录 2.添加lib包 3.在web.xml中配置DispatchServlet 这个就是主servlet. <?xml version="1.0 ...