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的路径且边不重复 在边双连通分量中 任意两 ...
随机推荐
- WebStorm、IntelliJ IDEA、JetBrains、PhpStorm、RubyMine、PyCharm
JetBrains旗下的产品: IntelliJ IDEA偏重于Java开发,旗舰产品,它可以通过(捆绑的或可下载的)插件的方式提供WebStorm和PhpStorm所有的功能.支持Scala和Gro ...
- Redmine管理项目3-调整用户显示格式
在 Redmine 中新建用户时是这样的: 必须指定姓氏.名字,然后 Redmine 默认是按“名字 姓氏”这种方式显示用户.比如“张三”,会显示成“三张”……看起来好别扭啊. 怎么调整呢,参看 Re ...
- Writing clean code is what you must do in order to call yourself a professional.
Clean Code A Handbook of Agile Software Craftsmanship
- magento获取ip地址
Mage::helper('coreservice')->getRequestIp()获取IP地址
- trove 开发者阅读翻译
介绍 Trove为OpenStack提供数据库的服务.它的设计运行完全符合OpenStack,目标是让用户能快速.轻松地利用关系数据库的特点,没有负担的处理复杂的管理任务.云用户和数据库管理员可以根据 ...
- Python基础之列表
列表的内置方法 1.append() 描述:用于在列表末尾添加新的对象. 示例: msg_list=["aaaa","bbbbb","cccccc&q ...
- 面试题-Java基础-布局管理器
1.什么是布局管理器? 布局管理器用来在容器中组织组件.
- C语言 · 分解质因数
问题描述 求出区间[a,b]中所有整数的质因数分解. 输入格式 输入两个整数a,b. 输出格式 每行输出一个数的分解,形如k=a1*a2*a3...(a1<=a2<=a3...,k也是从小 ...
- 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群(转载-2)
原文:http://www.cnblogs.com/PurpleDream/p/4510279.html 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群 前言: ...
- JDK各版本新增的主要特性
JDK1.5新特性: 1.自动装箱与拆箱: 2.枚举 3.静态导入,如:import staticjava.lang.System.out 4.可变参数(Varargs) 5.内省(Introspec ...