HDU_1242_Rescue
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1242
大意:迷宫搜索,'#'代表墙,'.'代表路,'x'代表守卫,每移动1格用1秒,杀死守卫用1秒,angel('a'表示)的朋友们(用'r'表示),要去救她,问最短时间为多少?
分析:迷宫搜索,dfs
总结:注意读题,之前做的时候以为只有一个朋友,其实有多个,所以用'a'去找'r'比较方便。注意输入,之前输入也有错误。
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
#define N 205
#define INF 0x7ffffff int n,m,minx;
int ex,ey;
char map[N][N];
bool vis[N][N];
int dir[][]= {{-,},{,},{,},{,-}}; bool inside(int x,int y)
{
if(x>=&&x<m&&y>=&&y<n)
return ;
return ;
} void dfs(int x,int y,int time)
{
if(map[x][y]=='r')
{
if(time<minx)
minx=time;
return;
}
if(map[x][y]=='#')
return;
if(time>minx)
return;
if(!inside(x,y))
return;
if(vis[x][y])
return;
vis[x][y]=;
for(int i=; i<; i++)
{
int mx=x+dir[i][];
int my=y+dir[i][];
if(map[mx][my]=='x')
dfs(mx,my,time+);
else
dfs(mx,my,time+);
}
vis[x][y]=;
} int main()
{
int sx,sy;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(vis,,sizeof(vis));
minx=INF;
for(int i=;i<m;i++)
scanf("%s",map[i]);
for(int i=; i<m; i++)
for(int j=; j<n; j++)
if(map[i][j]=='a')
{
sx=i;
sy=j;
}
//for(int i=0; i<m; i++)
// printf("%s\n",map[i]);
dfs(sx,sy,);
if(minx==INF)
printf("Poor ANGEL has to stay in the prison all his life.\n");
else
printf("%d\n",minx);
}
return ;
}
HDU_1242_Rescue的更多相关文章
随机推荐
- nodejs v8引擎c++编译版本号升级教程
原GCC版本号:4.4.7. 目标:升级GCC到4.8.2.以支持C++11. yum install gcc-c++ 获取GCC 4.8.2包:wget http://gcc.skazkaforyo ...
- canvas.clipPath canvas.clipRect() 无效的原因
今天发现有些机型不能做到像QQ 透明截图那样的功能,本来能够的.一看是部分机器所有都是灰色半透明遮挡住了,没中间的透明效果,. 并且我不是通过遮挡,我是採用 裁剪的方式,至于裁剪代码百度有相关知识,具 ...
- vmstat输出项解释
输出项的解释例如以下: procs * r列表示执行和等待cpu时间片段的进程数,这个值假设长期大约系统cpu个数.说明cpu不足 * b列表示在等待资源的进程数.比方正在等待IO或者内存交换等等 m ...
- 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例
服务器无法处理请求. ---> 未将对象引用设置到对象的实例. 简短说下我遇到的问题.webservice部署到服务器上后,访问方法报上面的错误,最终原因为改方法需要操作文件夹,加上了相应的权限 ...
- Flask 解析 Web 端 请求 数组
Web前台由 JavaScript 通过Ajax发送POST请求,当请求数据为数组时,Python Flask 做服务器时的解析如下: js: var ids = []; for (var i = 0 ...
- HDU-4643-GSM(DFS)
Problem Description Xiao Ming is traveling around several cities by train. And the time on the train ...
- 危险的input 微博的过去
更改uid post地址不变
- projecteuler---->problem=12----Highly divisible triangular number
title: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th trian ...
- windows console Kill PID 端口查看
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- xubuntu 17.04 和 iphone 6互传文件方法——使用libimobiledevice就可以像u盘一样操作文件了
I need to preface this by saying I'm also new to Linux, but I've got it working I think. The instruc ...