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的路径且边不重复 在边双连通分量中 任意两 ...
随机推荐
- 用php 进行对文件的操作 (上)
如何让自己磁盘中的文件夹和目录显示在网页上?那就来看一下,用php是怎么来操作他们的吧 php中文件,一般包含两块内容,文件和目录 先来一句一句的看代码,及他的作用 运行后看一下结果 file 指的是 ...
- C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息二
前言 这一篇实现snsapi_userinfo,写这篇时其实我是有疑惑的,因为我并没有调试成功,但是我反复检查程序和思路是没有问题的,因为我使用的测试公众号,群里一个伙计说他之前调试时用的也是测试公众 ...
- C# EnumHelper
using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection ...
- 打包apk java 虚拟机内存不足
解决方案:在android->sdk->build-tools-android-version 中有个 dx.bat dx.bat --dex 命令的dx.bat脚本有这样一句代码 REM ...
- EXCEL 数字统一转换成文本
将excel中的数字统一转换成文本形式.即添加‘. 1.点击数据-分列. 2.分隔符号-下一步. 3.选择文本识别符号,如“‘”分号. 4. 选中文本-完成.
- spark yarn任务的executor 无故 timeout之原因分析
问题: 用 spark-submit --master yarn --deploy-mode cluster --driver-memory 2G --num-executors 6 --execu ...
- Linq to Sql 左连接查询
var query = from t0 in context.ExpressSendMaster join t1 in context.Supplier on t0.SupplierCode equa ...
- Mysq 5.7l服务无法启动,没有报告任何错误
昨天系统崩溃了,然后重装了Mysql 5.7 安装步骤和遇到问题及解决方案. 去官网下载Mysql 5.7的解压包(zip),解压到你要安装的目录. 我的安装目录是:D:\Java\Mysql 安装步 ...
- spring+springmvc+mybatis整合框架搭建
由于例子是基于Maven搭建的,所以首先是pom.xml文件的依赖信息: <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- 第一百一十六节,JavaScript,DOM操作样式
JavaScript,DOM操作样式 一.操作样式 CSS作为(X)HTML的辅助,可以增强页面的显示效果.但不是每个浏览器都能支持最新的CSS能力.CSS的能力和DOM级别密切相关,所以我们有必要检 ...