hdu 5433 Xiao Ming climbing(bfs+三维标记)
Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can hardly escape. This mountain is pretty strange that its underside is a rectangle which size is n∗m and every little part has a special coordinate(x,y)and a height H. In order to escape from this mountain,Ming needs to find out the devil and beat it to clean up the curse. At the biginning Xiao Ming has a fighting will k,if it turned to Xiao Ming won't be able to fight with the devil,that means failure. Ming can go to next position(N,E,S,W)from his current position that time every step,(abs(H1−H2))/k 's physical power is spent,and then it cost 1 point of will. Because of the devil's strong,Ming has to find a way cost least physical power to defeat the devil. Can you help Xiao Ming to calculate the least physical power he need to consume.
The first line of the input is a single integer T(T≤), indicating the number of testcases. Then T testcases follow. The first line contains three integers n,m,k ,meaning as in the title(≤n,m≤,≤k≤). Then the N × M matrix follows. In matrix , the integer H meaning the height of (i,j),and '#' meaning barrier (Xiao Ming can't come to this) . Then follow two lines,meaning Xiao Ming's coordinate(x1,y1) and the devil's coordinate(x2,y2),coordinates is not a barrier.
For each testcase print a line ,if Xiao Ming can beat devil print the least physical power he need to consume,or output "NoAnswer" otherwise. (The result should be rounded to decimal places)
#
# #
# #
#
#
#
1.03
0.00
No Answer
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 56
#define inf 1e12
int n,m,k;
char mp[N][N];
int sgn(double e)
{
if(fabs(e)<eps)return ;
return e>?:-;
}
struct Node{
int x,y;
int t;
double v;
}st,ed;
double vis[N][N][N];
int M[N][N];
int dirx[]={,,-,};
int diry[]={,,,-};
void bfs(){
queue<Node>q;
st.v=;
q.push(st);
Node t1,t2;
vis[st.x][st.y][st.t]=;
while(!q.empty()){
t1=q.front();
q.pop();
if(t1.t<=) continue;
for(int i=;i<;i++){
t2=t1;
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
if(t2.x< || t2.x>=n || t2.y< || t2.y>=m) continue;
if(M[t2.x][t2.y] == -) continue; int num1=M[t2.x][t2.y];
int num2=M[t1.x][t1.y];
t2.v+=(abs(num1-num2)*1.0)/(t2.t);
t2.t--;
if(sgn(vis[t2.x][t2.y][t2.t]-t2.v)>){
vis[t2.x][t2.y][t2.t]=t2.v;
q.push(t2);
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%s",mp[i]);
for(int j=; j<m; j++)
if(mp[i][j]=='#')M[i][j]=-;
else M[i][j]=mp[i][j]-'';
} scanf("%d%d%d%d",&st.x,&st.y,&ed.x,&ed.y);
if(k<=){
printf("No Answer\n"); continue;
}
st.x--;
st.y--;
ed.x--;
ed.y--;
st.t=k;
st.v=;
//memset(vis,inf,sizeof(vis));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
for(int r=;r<=k;r++){
vis[i][j][r]=inf;
}
}
}
bfs();
double ans=vis[ed.x][ed.y][];
for(int i=;i<=k; i++)
ans=min(ans,vis[ed.x][ed.y][i]); if(sgn(ans-inf)>=){
printf("No Answer\n");
}
else{
printf("%.2lf\n",ans);
}
}
return ;
}
hdu 5433 Xiao Ming climbing(bfs+三维标记)的更多相关文章
- HDu 5433 Xiao Ming climbing (BFS)
题意:小明因为受到大魔王的诅咒,被困到了一座荒无人烟的山上并无法脱离.这座山很奇怪: 这座山的底面是矩形的,而且矩形的每一小块都有一个特定的坐标(x,y)和一个高度H. 为了逃离这座山,小明必须找到大 ...
- HDU 5433 Xiao Ming climbing 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...
- HDU 5433 Xiao Ming climbing dp
Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...
- HDU 5433 Xiao Ming climbing
题意:给一张地图,给出起点和终点,每移动一步消耗体力abs(h1 - h2) / k的体力,k为当前斗志,然后消耗1斗志,要求到终点时斗志大于0,最少消耗多少体力. 解法:bfs.可以直接bfs,用d ...
- HDU 4349 Xiao Ming's Hope 找规律
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/ ...
- hdu5433 Xiao Ming climbing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
- HDU 4349 Xiao Ming's Hope lucas定理
Xiao Ming's Hope Time Limit:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- hdu 4349 Xiao Ming's Hope 规律
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4349——Xiao Ming's Hope——————【Lucas定理】
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- HR系统+人脸识别
近期一直在写一套HR系统,这套HR系统和人脸识别相结合.全然杜绝取代刷卡的情况产生.系统的灵活性比較强,开发简洁高速. 例如以下是一些功能上的截图 考勤模块仅仅是列举当中一个请假申请的功能做为展示 ...
- android layout属性介绍
android:id 为控件指定对应的ID android:text 指定控件其中显示的文字,须要注意的是,这里尽量使用strings.xml文件其中的字符串 android:gravity 指定Vi ...
- IT English Collection(9) of Objective-C
1 前言 今天我们来解除一篇有关Objective-C的介绍文章,详情如下. 2 详述 2.1 原文 Objective-C defines a small but powerful set of e ...
- linux core dump学习
1. core dump是什么? core dump又叫核心转储,当操作系统收到特定的signal时, 会生成某个进程的core dump文件.这样程序员可以根据 已经生成的core dump文件来d ...
- 【转】Cocoa中的位与位运算
转自:http://www.tuicool.com/articles/niEVjy 介绍 位操作是程序设计中对位模式或二进制数的一元和二元操作. 在许多古老的微处理器上, 位运算比加减运算略快, 通常 ...
- CodeSmith使用总结--读取一个表试试
我感觉CodeSmith对于我的最大用途是不用我手动创建每个表的Model.BLL和DAL了,那些繁琐的工作真的让我很无语. CodeSmith要读取数据库中的表就要先连接数据库. 新建一个数据库连接 ...
- WebAPI中Message Handler与Filter的区别
两者最主要的区别是关注点不同.Message Handlers应用到HTTP Request,Filters仅应用到controller/action上. 如果某种行为应用到大多数的Request时, ...
- HDU 5904 - LCIS (BestCoder Round #87)
HDU 5904 - LCIS [ DP ] BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...
- 线段树练习 codevs 1080
/* codevs 1080 线段树练习 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 一行N个方格,开 ...
- 使用python发邮件
使用python发邮件 网上有很多发邮件的例子,本人在网上找了一份,稍加修改后使用 上源码 # encoding=utf-8 from email.mime.image import MIMEImag ...