HDU 1026 Ignatius and the Princess I (BFS)
题意 : 从(0,0)点走到(N-1,M-1)点,问最少时间。
思路 : BFS、、、、、
#include <stdio.h>
#include <string.h>
#include <queue>
#include <iostream> using namespace std ; struct node
{
int x,y ;
int tim ;
friend bool operator < (node a,node b)
{
return a.tim > b.tim ;
}
} temp,temp1;
int N,M ,t;
char mapp[][] ;
int vis[][] ;
int dir[][] = {{-,},{,},{,-},{,}} ; int BFS()
{
temp.x = ;
temp.y = ;
temp.tim = ;
priority_queue<node>Q ;
Q.push(temp) ;
// vis[0][0] = true ;
while(Q.size())
{
temp = Q.top() ;
Q.pop() ;
if(temp.x == N- && temp.y == M-) return temp.tim ;
for(int i = ; i < ; i++)
{
temp1.x = temp.x+dir[i][] ;
temp1.y = temp.y+dir[i][] ;
if(temp1.x >= && temp1.y >= && temp1.x <= N- && temp1.y <= M- && vis[temp1.x][temp1.y] == - && mapp[temp1.x][temp1.y] != 'X')
{
vis[temp1.x][temp1.y] = temp.x*M+temp.y ;
if(mapp[temp1.x][temp1.y] == '.')
temp1.tim = temp.tim+ ;
else
temp1.tim = temp.tim + mapp[temp1.x][temp1.y]-''+ ;
Q.push(temp1) ;
}
}
}
return - ;
}
void print(int x,int y)
{
if(x == && y == )
return ;
int xx = vis[x][y]/M ;
int yy = vis[x][y]%M ;
print(xx,yy) ;
printf("%ds:(%d,%d)->(%d,%d)\n",t++,xx,yy,x,y) ;
if(mapp[x][y] >= '' && mapp[x][y] <= '')
{
while(mapp[x][y] -'' > )
{
printf("%ds:FIGHT AT (%d,%d)\n",t++,x,y) ;
mapp[x][y] -- ;
}
}
}
int main()
{
while(~scanf("%d %d",&N,&M))
{
for(int i = ; i < N ; i++ )
scanf("%s",mapp[i]) ;
memset(vis,-,sizeof(vis)) ;
int timee = BFS() ;
if(timee == -)
{
printf("God please help our poor hero.\nFINISH\n") ;
}
else
{
t = ;
printf("It takes %d seconds to reach the target position, let me show you the way.\n",timee) ;
print(N-,M-) ;
printf("FINISH\n") ;
}
}
return ;
}
HDU 1026 Ignatius and the Princess I (BFS)的更多相关文章
- hdu 1026 Ignatius and the Princess I(bfs)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 1026 Ignatius and the Princess I(BFS+优先队列)
Ignatius and the Princess I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- hdu 1026:Ignatius and the Princess I(优先队列 + bfs广搜。ps:广搜AC,深搜超时,求助攻!)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 1028 Ignatius and the Princess III(母函数)
题意: N=a[1]+a[2]+a[3]+...+a[m]; a[i]>0,1<=m<=N; 例如: 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + ...
- HDU-1026 Ignatius and the Princess I(BFS) 带路径的广搜
此题需要时间更少,控制时间很要,这个题目要多多看, Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Me ...
- HDU 1026 Ignatius and the Princess I(带路径的BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:给出一个迷宫,求出到终点的最短时间路径. 这道题目在迷宫上有怪物,不同HP的怪物会损耗不同的时间,这 ...
- HDU 1026 Ignatius and the Princess I (广搜)
题目链接 Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius ...
- hdu 1026 Ignatius and the Princess I(优先队列+bfs+记录路径)
以前写的题了,现在想整理一下,就挂出来了. 题意比较明确,给一张n*m的地图,从左上角(0, 0)走到右下角(n-1, m-1). 'X'为墙,'.'为路,数字为怪物.墙不能走,路花1s经过,怪物需要 ...
- HDU 1029 Ignatius and the Princess IV(数论)
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...
随机推荐
- Ubuntu下编译内核
一.下载源代码和编译软件的准备 下载内核源代码:http://www.kernel.org/ 注意,点击2.6.25内核的F版,即完整版. 如果你懒得去网站点联接,运行下列命令: 代码: $cd ~ ...
- WIndows7 多版本
Windows7 安装U盘 删除source\ei.cfg 以后开机安装会提示安装的版本
- Android操作系统11种传感器介绍
我们依次看看这十一种传感器 1 加速度传感器 加速度传感器又叫G-sensor,返回x.y.z三轴的加速度数值. 该数值包含地心引力的影响,单位是m/s^2. 将手机平放在桌面上,x轴默认为0,y轴默 ...
- [转]ldconfig几个需要注意的地方
[转]ldconfig几个需要注意的地方 http://www.cnblogs.com/arci/archive/2011/03/19/1988952.html 1. 往/lib和/usr/lib里面 ...
- Linux下强制修改root密码方法(图)
如果Linux操作系统的root密码,那怎么办呢?方法很多,下面再给大家介绍一种. [1] 进入以下画面后,按下e按钮,进入编辑模式: [2]进入以下的画面后,选择如下所示的选项,再次按下e按钮: 然 ...
- Graceful degradation versus progressive enhancement
http://ued.taobao.org/blog/2008/10/understanding-progressiveen-hancement-chs-translation/ http://www ...
- C++中数组求偏移量计算公式
已知数组:type A[10][5]A[0][0] --A[8][4]面试常考:数组定义A[0....x][0...y]已知A[m][n] --求A[k][l]的地址: &A[m][n] ...
- mui开发webapp(1)
mui开发注意事项 Mui HTML5开发框架 mui是一个高性能的HTML5开发框架,从UI到效率,都在极力追求原生体验:这个框架自身有一些规则,刚接触的同学不很熟悉,特总结本文:想了解mui更详细 ...
- 阿里云:linux 一键安装web环境
参考地址:http://www.cnblogs.com/ada-zheng/p/3724957.html
- android开发 wifi开发工具类
import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Iterator; import j ...