#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#define INPUT
using namespace std;
/**
Problem : ZOJ1649 - Rescue
Begin Time : 7:00 p.m. 17th/Mar/2012
End Time : 22:17 17th/Mar/2012
Knowledge:
BFS+标记技巧
Thought:
其实是反着来搜索的,是点a去找点r们,而不是点r去找点a
移动按照普通的深搜移动规则就好。
但是对于每个点是否已经访问过不是像往常那样
vis[i][j] = 1就完事儿了,我们在_time数组里判断某个点是否已经找过
换言之,只有当(i,j)访问(i,j+1)的时候,(i,j)到(i,j+1)的代价小于
原来(i,j+1)的代价才准许访问。
这点跟那个Nightmare是十分类似的。
其实也可以用优先队列来做。
Exp.:
ZOJ的数据是多组输入的,所以一定要
while(scanf("%d") != EOF )
*/
struct node
{
int x;
int y;
int _time;
};
const int dx[] = {0,0,-1,1};
const int dy[] = {1,-1,0,0};
char maze[210][210];
int _time[210][210];
node que[1000000];
int startx,starty;
bool check(node tmp,int N,int M)
{
if ( tmp.x >= N || tmp.x < 0
|| tmp.y >= M || tmp.y < 0
|| maze[tmp.x][tmp.y] == '#'
||
(_time[tmp.x][tmp.y] != 0 && _time[tmp.x][tmp.y] < tmp._time )
)
return false;
return true;
}
void Solve(int N,int M)
{
bool isFound =false;
int front = 1, rear = 2;
int btime = 1000000;
node tmp,tmp1;
tmp.x = startx;
tmp.y = starty;
tmp._time = 0;
que[front] = tmp;
while( front < rear )
{
tmp = que[front];
_time[tmp.x][tmp.y] = tmp._time;
if( maze[tmp.x][tmp.y] == 'r' )
{
///找到朋友们
isFound = true;
if ( _time[tmp.x][tmp.y] < btime )
btime = _time[tmp.x][tmp.y];
}
///为某个点打上时间标记。
for(int i = 0 ; i < 4 ; i++)
{
tmp1.x = tmp.x + dx[i];
tmp1.y = tmp.y + dy[i];
if( tmp1.x < N && tmp1.x >= 0
&& tmp1.y < M && tmp1.y >= 0)
{
if( maze[tmp1.x][tmp1.y] == 'x')
tmp1._time = tmp._time + 2;
else
tmp1._time = tmp._time + 1;
if( check(tmp1,N,M) )
{
que[rear++] = tmp1;
}
}
}
front++;
}
if( isFound )
{
printf("%d\n",btime);
}
else
{
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
}
int main()
{
int n,m;
node tp;
char t[5];
#ifdef INPUT
freopen("b:\\acm\\zoj1649\\input.txt","r",stdin);
#endif
while ( scanf("%d%d",&n,&m) != EOF )
{
memset(maze,0,sizeof(maze));
memset(_time,0,sizeof(_time));
memset(que,0,sizeof(que));
gets(t);
for(int i = 0 ; i < n ; i++)
{
gets(maze[i]);
// gets(t);
for ( int j = 0 ; j <m ; j++)
{
if( maze[i][j] == 'a' )
{
startx = i;
starty = j;
}
}
}
Solve(n,m);
}
// cout << "Hello world!" << endl;
return 0;
}
相关推荐
Python实现课程时间表
用Python实现课程表功能
ZOJ 1649 解题报告
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 5
pgpool-II踩坑日记两则
最近结合pgpool-II进行postgreSQL高可用的部署,过程非常煎熬,作为新手,公司也没有前辈熟悉postgreSQL,只能自己摸索。好在已经搞明白了,把困扰我很长时间的两个问题分享一下。 1. show pool_nodes 第一个问题就是 show pool_nodes 的使用,照着教程建好后,在哪里执行这个指令呢?我在pg服务器上怎么执行这个指令都显示 ERROR: unrecognized configuration parameter "pool_nodes",一度怀疑人生。翻阅了很多资料
ZOJ 1649 Rescue
本题要求从r 位置出发到达Angel所在位置并且所需时间最少,适合采用BFS求解。但是BFS算法求出来的最优解通常是步数最少的解,而在本题中,步数最少的解不一定是最优解. 在本题中,并没有使用标明各位置是否访问过的状态数组visited,也没有在BFS过程中将访问过的相邻位置设置成不可再访问,那么BFS过程会不会无限搜索下去呢?实际上是不会的,因为从某个位置出发判断是否需要将它的相邻位
保姆级教程:用Unidbg搞定阿里系App的x-sign和长x-mini-wua签名(附完整Java代码)
本文详细介绍了如何使用Unidbg框架模拟执行阿里系App的原生库,生成关键的x-sign和x-mini-wua签名参数。通过完整的Java代码示例和实战技巧,帮助开发者高效实现签名算法,适用于安全研究、数据分析和第三方应用开发场景。
计算机导论期末知识点及试题总结 [近三万字总结 · 全]
计算机网络:计算机网络是利用通信线路连接起来相互独立的计算机的集合,其主要目的是实现数据通信和资源共享。 计算机病毒:破坏计算机功能或数据,影响计算机使用,并能自我复制的一组计算机指令或程序。 操作系统:操作系统是由程序和数据结构组成的大型系统软件,它负责计算机的全部软硬件的资源分配,调度和管理,控制各类程序的正常执行,并为用户使用计算机提供良好的环境。 高速缓冲储存器(Cache):位于cpu和内存之间的储存器,其特点是速度快,目的是是储存器的速度与cpu的速度相匹配。 总线:若干信号线的集合,是
【2017 BSUIR Semifinal D】Friends rescue 题解
题目大意 有一个池塘,中间有 n 行 n+1 列的石头阵。 连边只能连相邻的格子,相邻定义为四连通。 现在左边第一列石头已经跟左边大陆 L 相连,右边最后一列石头已经跟右边大陆 R 相连。问剩下的有多少种连边方式,使得 L 与 R 连通。 n≤42
GPU 资源池化云平台解决方案
定义与特点Kubernetes是一个开源的容器编排和管理平台,通过提供自动化和声明式的方式来部署、扩展、维护和运行应用程序。它支持跨多个主机和集群部署容器,确保应用程序的高可用性和可扩展性。Kubernetes提供了丰富的功能和插件,允许用户根据自己的需求进行定制和扩展。架构与组件控制平面(Control Plane):负责集群的决策(如调度)和集群状态的检测与响应。
Rescue OJ (拯救被困的天使)
题目大意: 有个鸟人不小心beihuaidanzhua
通过miniconda conda安装jupyer的时候报错: InvalidArchiveError(“Error with archive
摘要:本文针对Windows系统使用Conda时出现的InvalidArchiveError错误(文件路径过长或压缩包损坏),提供了解决方案。建议以管理员身份运行PowerShell并执行命令启用长路径支持(LongPathsEnabled),然后重启电脑或终端。作者通过该方法成功解决了jupyter安装问题。附有错误截图和解决后的成功截图。
V-Mamba:2D 选择性扫描状态空间模型图像分类
V-Mamba CIFAR-10 分类链路:32² RGB → Stem Conv (3→64ch, stride2→16²) → VMambaBlock ×4 (SS2D 四方向 → Mamba S6 扫描 → MLP) → GAP → Linear → 10 类。核心贡献:SS2D 四方向扫描将 2D 空间建模转为 4 个 1D 序列, 计算复杂度从 O(N²) 降至 O(N)。建议先从 CIFAR-10 dim=64 depth=4 验证 SSM 收敛性;
Rescue (ZOJ - 1649 )
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to...
无人驾驶Autoware导读
认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长!本文先对无人驾驶Autoware介绍做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章提示:以下是本篇文章正文内容。
zoj1649 Rescue
本题是多个朋友 "r" 去牢房解救天使 "a" 的故事,"#"是墙,"."是路,路的话走一格需要一步的时间,"x"是守卫,需要先杀死守卫再走过去,耗费两步的时间,问哪一个朋友能在最少步数把天使救出来。 本来很天真,用DFS写了一个,果断TLE了。 后来用BFS写,并且写的时候有一个取巧的地方,就是让天使去寻找朋友,而不是让朋友寻找天使,大概思路是每次把最少步数的节点赋给 节点 t ,然后判断该
最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版
Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
ACM ZOJ 1649 (Rescue)
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 思路一 宽度优先搜索,用优先队列实现,这个应该很容易想到。 思路二 转换成最短路问题,先用一个矩阵存储matrix输入的字符,然后遍历矩阵,找到两个相邻的点:如果两个点中有#,则距离为INF;如果有且仅有1个x,则距离为1.5;如果有两个x,则距离为
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
hdu 1242 zoj1649 Rescue 优先队列
Problem DescriptionAngel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.Angel'...
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
zoj1649_Rescue
#include #include using namespace std; #define MAX 202 struct node { int i; int j; }; int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; int martic[MAX][MAX]; int mark[MAX][MAX]; node queue[40004]; int bfs(int x,int y,int a,int b) { if(x==a&&y==b) return 0; node t
ZOJ 1649 Rescue
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put in prison by Molig
zoj 1649 Rescue bfs
Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M Angel's friends want to sa
Rescue ZOJ - 1649 (bfs 优先队列)
Rescue ZOJ - 1649 Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.Angel's...
ZOJ Problem Set - 1649 Rescue BFS+优先队列
ZOJ Problem Set - 1649 Rescue题目描述: 题目链接:ZOJ Problem Set - 1649 Rescue题目大意: Angel被关在牢房里,你要从给定的地方出发在最短时间内找到天使。单位时间内能向上下左右移动一个。并且牢房里理由狱警,遇到狱警所消耗时间+1。如果,没有办法找到Angel,那么输出:Poor ANGEL has to stay in the pri
ZOJ 1649: Rescue(BFS)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=649 Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are ...
简单BFS ZOJ 1649 Rescue
题意:r->a用时最少,经过'x'需2s,经过'.'1s. 思路:用BFS,但是,显然,走的步数少并不代表用的时间少。因此,标记走到每个点用的最少时间,若下次要走到该点,必须比该点用时更少(同时更新该点)。#include #include #include #include #include #include #include #include #include #inclu
ZOJ1649 营救Rescue (BFS)
题目链接http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649题意Angel被抓了,并且被关在监狱里。监狱可以用一个NxM的矩阵来表示。监狱由NxM个方格表示,每个方格可能为墙壁、道路、警卫、她的朋友和她。angel的朋友可以向上、下、左、右四个方向走,走到为道路的方格需要时间1,走到有警卫的方格需要时间2(杀死警卫需要时间
BFS - Rescue ZOJ - 1649
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach
zoj 1649 Rescue
题目链接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98233#problem/A 题目大意:Angle 的朋友想去营救Angle,其任务是到Angle的位置,Angle 的朋友向上,下,左,右移动一步用时1个单位时间,杀死警卫需要用1个时间。计算Angle的朋友营救Angle至少需要多长的时间。 “a” 代表Angle的位置。
2048




被折叠的 条评论
为什么被折叠?



