BFS..第一次使用C++ STL的队列来写广搜。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = ;
struct Point{ int time, x, y; };
queue<Point> Q;
char mapp[maxn][maxn];
int mt[maxn][maxn];
int dir[][] = { { -, }, { , }, { , - }, { , } };
int main()
{
int n, m, i, j, sx, sy, ex, ey, ans;
while (~scanf("%d%d", &n, &m))
{
for (i = ; i < n; i++) scanf("%s", mapp[i]);
for (i = ; i < n; i++)
{
for (j = ; j < m; j++)
{
mt[i][j] = 0x7FFFFFFF;
if (mapp[i][j] == 'a') sx = i, sy = j;
if (mapp[i][j] == 'r') ex = i, ey = j;
}
}
Point ss; ss.time = ; ss.x = sx; ss.y = sy;
Q.push(ss);
ans = 0x7FFFFFFF;
while (!Q.empty())
{
Point h, t;
h = Q.front(); Q.pop();
if (h.x == ex&&h.y == ey&&h.time < ans) ans = h.time;
for (i = ; i < ; i++)
{
int xx = h.x + dir[i][], yy = h.y + dir[i][];
if (xx >= && xx <= n-&&yy >= && yy <= m-)
{
if (mapp[xx][yy] != '#')
{
if (mapp[xx][yy] == 'x')
{
if (h.time + < mt[xx][yy])
{
t.time = h.time + ;
t.x = xx; t.y = yy;
mt[xx][yy] = h.time + ;
Q.push(t);
}
}
else
{
if (h.time + < mt[xx][yy])
{
t.time = h.time + ;
t.x = xx; t.y = yy;
mt[xx][yy] = h.time + ;
Q.push(t);
}
}
}
}
}
}
if (ans != 0x7FFFFFFF)printf("%d\n", ans);
else printf("Poor ANGEL has to stay in the prison all his life.\n");
}
return ;
}

zoj 1649 Rescue的更多相关文章

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

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

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

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

  3. BFS zoj 1649

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

  4. ZOJ 1649:Rescue(BFS)

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

  5. HDU 1242 Rescue(BFS),ZOJ 1649

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

  6. ZOJ 649 Rescue(优先队列+bfs)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. ZOJ 3545 Rescue the Rabbit(AC自动机+状压DP)(The 2011 ACM-ICPC Asia Dalian Regional Contest)

    Dr. X is a biologist, who likes rabbits very much and can do everything for them. 2012 is coming, an ...

  8. Zoj 3545 Rescue the Rabbit(ac自己主动机+dp)

    标题效果: 鉴于DNA有一个正确的顺序值.请构造一个长度I的DNA在这个序列使DNA正确的顺序值极大.它被认为是负的输出噼啪. .. IDEAS: 施工顺序是,ac己主动机上走,求最大要用到dp dp ...

  9. ZOJ 4097 Rescue the Princess

    在这个物欲横流的社会 oj冷漠无情 只有这xx还有些温度 越界就越界吧  wrong 怎么回事.... 给出一个图 然后给出q次询问 问是否存在v和w分别到u的路径且边不重复 在边双连通分量中 任意两 ...

随机推荐

  1. 【微信开发】微信公众平台接入及绑定提示“请求URL超时”的解决办法

    成为微信开发者的第一步--微信公众平台接入 第一步:填写服务器配置 在开发->基本配置处启用服务器配置.修改配置 其中URL是开发者用来接收微信消息和事件的接口URL. Token可由开发者可以 ...

  2. [ios-必看] iOS 下实现解压缩

    http://blog.csdn.net/lyy_whg/article/details/11971581 http://blog.sina.com.cn/s/blog_833996210100udk ...

  3. React入门实例

    前言 React 的核心思想是:封装组件,各个组件维护自己的状态和UI,当状态变更,自动重新渲染整个组件. 理解:react首先值得拍手称赞的是它所有的开发都基于一个组件(component),组件和 ...

  4. Struts1和Struts2的区别和对比

    Struts1和Struts2的区别和对比: Action 类: • Struts1要求Action类继承一个抽象基类.Struts1的一个普遍问题是使用抽象类编程而不是接口. • Struts 2  ...

  5. USACO 3.3 Camelot

    CamelotIOI 98 Centuries ago, King Arthur and the Knights of the Round Table used to meet every year ...

  6. Lamada转化字符类型

    //SN为字符串类型,将其转换成Int等数字类型 ---第一种 List<Testing_Report_Enclosureslist> enclosuresList = _db.Testi ...

  7. [Usaco 再次除草]

    以后都用自己的号交吧 免得掉人品 Noip2016就是一个见证 一步一个脚印的刷 noip没把前两题稳拿就刷牛头..   bzoj1230 线段树打翻转标记,练手感 bzoj1231 状态压缩 预处理 ...

  8. Nuget 学习二

    打包自己的类库 准备工作: 1)nuget 账号: https://www.nuget.org/ 2)nuget 包管理器 点击下载:NuGetPackageExplorer,安装完应该是酱紫. 开始 ...

  9. ios微信支付成功后点击左上角返回不走回调的问题

    最近做微信支付发现ios9以后出现的跳转其他app后左上角有返回xxx功能会影响微信支付回调,情况如图 返回后不走下面的方法 - (BOOL)application:(UIApplication *) ...

  10. fiddler还是浏览器的问题

    当我在浏览器里输入http://localhost/infomanage/price?cityid=1&cateid=246&timer=3 后端接收的参数是timer的时候,浏览器会 ...