题目链接

题意 : 从(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)的更多相关文章

  1. 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 ...

  2. HDU 1026 Ignatius and the Princess I(BFS+优先队列)

    Ignatius and the Princess I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  3. 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 ...

  4. 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 + ...

  5. HDU-1026 Ignatius and the Princess I(BFS) 带路径的广搜

      此题需要时间更少,控制时间很要,这个题目要多多看, Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Me ...

  6. HDU 1026 Ignatius and the Princess I(带路径的BFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:给出一个迷宫,求出到终点的最短时间路径. 这道题目在迷宫上有怪物,不同HP的怪物会损耗不同的时间,这 ...

  7. HDU 1026 Ignatius and the Princess I (广搜)

    题目链接 Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius ...

  8. hdu 1026 Ignatius and the Princess I(优先队列+bfs+记录路径)

    以前写的题了,现在想整理一下,就挂出来了. 题意比较明确,给一张n*m的地图,从左上角(0, 0)走到右下角(n-1, m-1). 'X'为墙,'.'为路,数字为怪物.墙不能走,路花1s经过,怪物需要 ...

  9. HDU 1029 Ignatius and the Princess IV(数论)

    #include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...

随机推荐

  1. chkconfig 命令详解

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法: chkconfig [--a ...

  2. Effiective C++ (一)

    最近在看Effective  C++ ,同时将总结一下里边的重要知识点: ##########################    module  1    #################### ...

  3. React Native相关

    安装相关工具参考(视频):http://ninghao.net/course/3001?a=26 学习参考:http://reactnative.cn/ 学习参考:http://www.ruanyif ...

  4. swift学习(二)--基本运算符、字符串、集合操作

    在这一篇博客里面,我想要介绍一下swift里面一些常用的基本运算符,还有涉及到的字符串,集合操作.你会发现在swift里面还是有许多其他语言所不具有的特性运算操作的. 首先最基本的+,-,*,/,&g ...

  5. Android的一些常用命令提示符(cmd)指令

    在<Android基础之用Eclipse搭建Android开发环境和创建第一个Android项目>中我曾介绍过如何给Android SDK配置环境变量,现在它就有用武之地了,我们可以直接在 ...

  6. (转)ZooKeeper 笔记(1) 安装部署及hello world

    ZooKeeper 笔记(1) 安装部署及hello world   先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.or ...

  7. mysql安装/启动报错汇总

    2016/9/6补充 初始化报错: # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysq ...

  8. [shell基础]——find命令

    find命令选项 -name 按照文件名查找 -type 查找某一类型的文件(b 代表设备块:d 目录:c 字符设备文件:l 符号(软)链接文件:f 普通文件) -size 查找文件长度或者大小 -p ...

  9. 轻松解决在一个虚拟主机上运行多个 ASP.NET 网站应用

    不知道有没有朋友像我一样会遇到这样一个问题: 在网上购买 .NET 空间,由于虚拟主机的限制,你并不能把某个目录设为一个独立的应用,或者一些价格比较高的空间,虽然可以设置,但数量也是有限的.这个问题导 ...

  10. 关于 Google Chrome 中的全屏模式和 APP 模式

    前言:我一直在纠结这篇文章是否应该归类在「前段开发」的范围内,哈哈! 前段时间做了一个项目,涉及到一个要全屏模式去访问网页的需求,因为 Google Chrome 的效率不错,而且专门为 Chrome ...