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",& ...
随机推荐
- SSH使用缩写
需要经常ssh到其它机器上,但如果每次都使用主机命名或ip地址,那挺难受的.这里有2个方法可以在ssh登陆时缩写(简写)主机名. 1. 在~/.ssh中添加config文件 [toughhou@hd1 ...
- Gearman 安装使用教程
Gearman是一个分发任务的程序框架,可以用在各种场合,Gearman更偏向于任务分发功能.它的任务分布非常简单,简单得可以只需要用脚本即可完成. Gearman 分布式任务实现原理上只用到2个字段 ...
- Android--获取标题栏,状态栏,屏幕高度
获取状态栏高度 Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int ...
- Zybo智能小车识别图像中的文字
智能小车识别图像中的文字 [TOC] 运行平台 这次的内容是基于Xilinx公司的Zybo开发板以及其配套的Zrobot套件开发 Zybo上面的sd卡搭载了Ubuntu12.04LTS的linux版本 ...
- TFT LCD 参数详解
我的板子设置HCLK=100M因此CLKVAL= int(HCLK/(VCLK*2)-1),其中VCLK即上图的DCLK=6.4M, CLKVAL="int"(100/12.8-1 ...
- json 读写 swift
// // ViewController.swift // json读写 // // Created by mac on 15/7/14. // Copyright (c) 2015年 fangyuh ...
- [shell基础]——整数比较;字符串比较;文件测试;逻辑测试符
整数比较方法一:[ ] 或 [[ ]] (1) 此方法需要使用整数比较运算符.[标注:equal 等于 greater 大于 less-then 小于] (2) 使用时一定要注意前后一 ...
- 使用VBA实现Excel自杀功能
曾经看到过一个“Excel-Home”出品的“关于Excel自杀功能”的视频教程,经认真学习后,我写下了自己的代码,分享于此. 实现思路: 使用VBA创建一个隐藏的名称,记录当前工作簿打开的次数,如果 ...
- JQuery 对 Select option 的操作---转载
<select id="selectID" > <option value="1">1</option> <optio ...
- VBS基础篇 - 内置函数
Date/Time 函数 函数 描述 CDate 把有效的日期和时间表达式转换为日期(Date)类型. Date 返回当前的系统日期. DateAdd 返回已添加指定时间间隔的日期. DateDiff ...