zoj 1649 Rescue
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的更多相关文章
- zoj 1649 Rescue (BFS)(转载)
又是类似骑士拯救公主,不过这个是朋友拯救天使的故事... 不同的是,天使有多个朋友,而骑士一般单枪匹马比较帅~ 求到达天使的最短时间,杀死一个护卫1 units time , 走一个格子 1 unit ...
- ZOJ 1649 Rescue(有敌人迷宫BFS)
题意 求迷宫中从a的位置到r的位置须要的最少时间 经过'.'方格须要1s 经过'x'方格须要两秒 '#'表示墙 因为有1s和2s两种情况 须要在基础迷宫bfs上加些推断 令到达每一个点的时间初 ...
- BFS zoj 1649
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 //hnldyhy(303882171) 11:12:46 // z ...
- ZOJ 1649:Rescue(BFS)
Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
- ZOJ 649 Rescue(优先队列+bfs)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 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 ...
- Zoj 3545 Rescue the Rabbit(ac自己主动机+dp)
标题效果: 鉴于DNA有一个正确的顺序值.请构造一个长度I的DNA在这个序列使DNA正确的顺序值极大.它被认为是负的输出噼啪. .. IDEAS: 施工顺序是,ac己主动机上走,求最大要用到dp dp ...
- ZOJ 4097 Rescue the Princess
在这个物欲横流的社会 oj冷漠无情 只有这xx还有些温度 越界就越界吧 wrong 怎么回事.... 给出一个图 然后给出q次询问 问是否存在v和w分别到u的路径且边不重复 在边双连通分量中 任意两 ...
随机推荐
- TypeScript 中的 SOLID 原则
下面的文章解释了正确使用 TypeScrip的 SOLID原则. 原文地址:https://samueleresca.net/2016/08/solid-principles-using-typesc ...
- glib实践篇:接口定义与实现
前言: 在上一篇讲解了基于glib实现抽象和继承后,当然这篇就得讲讲接口类型啦! 在JAVA中接口更多的弥补了其单继承所带来的缺陷,使其能够扩展很多功能,同时又不破坏它的结构.其实接口就是一种协议,在 ...
- MATLAB的符号运算基础
在数学运算中,运算的结果如果是一个数值,可以称这类运算为数值运算:如果运算结果为表达式,在MATLAB中称为符号运算,符号计算是对未赋值的符号对象(可以是常数.变量.表达式)进行运算和处理.MATLA ...
- mysql添加为成绩表添加名次
对于一种这样的表,为score添加名次
- Jenkins配置和使用
之前整理了Jenkins的下载和安装过程,有需要的可以参考我的博客,地址: http://www.cnblogs.com/luchangyou/p/5981884.html 接下来整理一下Jenk ...
- js-数据转换
<script type="text/javascript"> var msg = '{"code": 0, "data": 2 ...
- Junit4单元测试之高级用法
Junit单元测试框架是Java程序开发必备的测试利器,现在最常用的就是Junit4了,在Junit4中所有的测试用例都使用了注解的形式,这比Junit3更加灵活与方便.之前在公司的关于单元测试的培训 ...
- C#下在图片文件本地
//C#下载图片文件到本地,c#,c#下载,下载图片,下载文件,下载函数// 从图片地址下载图片到本地磁盘// 将二进制文件保存到磁盘 using System;using System.Drawin ...
- Playmaker 基础使用与案例操作
首先是把下载好的插件导入Unity工程中. ▼导入完成后第一个动作就是检查下拉菜单里面是否已经增加了Playmaker的功能,如果在安装后没看到Playmaker的菜单,一般情况下直接点击菜单上的空白 ...
- 第八章 监控 Zabbix
1.1 YUM部署 Zabbix 2.4 1. 前期准备(省略) l Yum源的配置 cd /etc/yum.repos.d/; mkdir old;mv ./* old/ rpm -Uvh ...