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的路径且边不重复 在边双连通分量中 任意两 ...
随机推荐
- ruby将mysql查询到的数据保存到excel
require "win32ole" require 'pathname' require 'mysql2' excel = WIN32OLE.new('excel.applica ...
- GridControl的单元格中以buttonEdit实现文字和图片按钮并存的效果
话不多说,先上效果图 对于第一列的效果是如何实现的就不多说了,网上有很多例子 重点是第三列的效果实现方法,代码如下 private void GridSet() { DevExpress.XtraEd ...
- C++ STD inner_product函数
C++ STD函数 inner_product是c++标准库封装的一个函数. 函数原型: 函数1: inner_product(beg1, end1, beg2, init) 函数2: inner ...
- 讲解——Trie树(字典树)
Trie树(字典树) 一.引入 字典是干啥的?查找字的. 字典树自然也是起查找作用的.查找的是啥?单词. 看以下几个题: 1.给出n个单词和m个询问,每次询问一个单词,回答这个单词是否在单 ...
- 第一百三十三节,JavaScript,封装库--弹出登录框
JavaScript,封装库--弹出登录框 封装库,增加了两个方法 yuan_su_ju_zhong()方法,将获取到的区块元素居中到页面,chuang_kou_shi_jian()方法,浏览器窗口事 ...
- HMM 前向后向算法(转)
最近研究NLP颇感兴趣,但由于比较懒,所以只好找来网上别人的比较好的博客,备份一下,也方便自己以后方便查找(其实,一般是不会再回过头来看的,嘿嘿 -_-!!) 代码自己重新写了一遍,所以就不把原文代码 ...
- shell 文件中列的整合成一个文件
原文件 第一种方法 [root@wxb- jt]# paste -d "," b c d ,q, , ,e, ,r, ,t, [root@wxb- jt]# paste b c d ...
- linuxlab下虚拟板与主机通信
- 面向对象UML中类关系
如果你确定两件对象之间是is-a的关系,那么此时你应该使用继承:比如菱形.圆形和方形都是形状的一种,那么他们都应该从形状类继承而不是聚合.如果你确定两件对象之间是has-a的关系,那么此时你应该使用聚 ...
- WPF中TextBox的PreviewMouseLeftButtonUp事件
当使用TextBox的PreviewMouseLeftButtonUp事件时(例如,鼠标点击进入TextBox时,清除当前的输入内容),会很意外地发现,这时候不论怎么点击都无法点击到其他控件,焦点一直 ...