hdu5433 Xiao Ming climbing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 438 Accepted Submission(s): 108
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 0 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.
indicating the number of testcases.
Then T testcases
follow.
The first line contains three integers n,m,k ,meaning
as in the title(1≤n,m≤50,0≤k≤50).
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.
otherwise.
(The result should be rounded to 2 decimal places)
4 4 5
2134
2#23
2#22
2221
1 1
3 3
4 4 7
2134
2#23
2#22
2221
1 1
3 3
4 4 50
2#34
2#23
2#22
2#21
1 1
3 3
0.00
No Answer
这题用宽搜做,用minx[x][y][d]表示走到(x,y)且剩余斗志为d的最少体力,bfs的过程中,只有满足边界条件并且下一步算出来的值要小于min[xx][yy][d]时才把这个点放入队列。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 999999999
#define maxn 10050
char gra[55][55];
int vis[55][55];
int tab[10][2]={0,1,-1,0,0,-1,1,0};
int n,m,k,x3,x2,y3,y2;
struct node{
double tili;
int x,y,douzhi;
}q[1111111];
double minx[55][55][55];
void bfs()
{
int i,j,front,rear,x,y,xx,yy,douzhi,dou;
double tili,ti;
front=rear=1;
q[front].x=x3;q[front].y=y3;q[front].tili=0;q[front].douzhi=k;
while(front<=rear){
x=q[front].x;y=q[front].y;tili=q[front].tili;douzhi=q[front].douzhi;
front++;
//printf("%d %d %.2f %d\n",x,y,tili,douzhi);
if(x==x2 && y==y2){
continue;
}
for(i=0;i<4;i++){
xx=x+tab[i][0];yy=y+tab[i][1];
if(xx>=1 && xx<=n && yy>=1 && yy<=m && gra[xx][yy]!='#'){
ti=tili+fabs(gra[xx][yy]-gra[x][y])/(double)douzhi;
dou=douzhi-1;
if(dou==0 || ti>=minx[xx][yy][dou]){
continue;
}
minx[xx][yy][dou]=ti;
rear++;
q[rear].x=xx;q[rear].y=yy;q[rear].tili=ti;q[rear].douzhi=dou;
}
}
}
}
int main()
{
int i,j,T,h;
double ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=n;i++){
scanf("%s",gra[i]+1);
}
scanf("%d%d%d%d",&x3,&y3,&x2,&y2);
if(k==0){
printf("No Answer\n");continue;
}
if(x2==x3 && y2==y3){
printf("0.00\n");continue;
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
for(h=1;h<=k;h++){
minx[i][j][h]=inf;
}
}
}
minx[x3][y3][k]=0;
bfs();
ans=inf;
for(i=1;i<=k;i++){
if(ans>minx[x2][y2][i]){
ans=minx[x2][y2][i];
}
}
if(ans==inf){
printf("No Answer\n");
}
else printf("%.2f\n",ans);
}
return 0;
}
hdu5433 Xiao Ming climbing的更多相关文章
- 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 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...
- hdu 5433 Xiao Ming climbing(bfs+三维标记)
Problem Description Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can ...
- HDU 5433 Xiao Ming climbing
题意:给一张地图,给出起点和终点,每移动一步消耗体力abs(h1 - h2) / k的体力,k为当前斗志,然后消耗1斗志,要求到终点时斗志大于0,最少消耗多少体力. 解法:bfs.可以直接bfs,用d ...
- HDu 5433 Xiao Ming climbing (BFS)
题意:小明因为受到大魔王的诅咒,被困到了一座荒无人烟的山上并无法脱离.这座山很奇怪: 这座山的底面是矩形的,而且矩形的每一小块都有一个特定的坐标(x,y)和一个高度H. 为了逃离这座山,小明必须找到大 ...
- HDU 4349 Xiao Ming's Hope lucas定理
Xiao Ming's Hope Time Limit:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- Hdu4349 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 规律
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) ...
随机推荐
- 《计算机组成原理 》& 《计算机网络》& 《数据库》 Roadmap for self-taugh student
计算机组成原理: UCB的这门课绝对是不错的资源. Great Ideas in Computer Architecture (Machine Structures) B站:https://www.b ...
- Java 使用URL类通过url下载网络资源
主要用到的类 地址类: URL http类: HttpURLConnection 输入流: InputStream 输出流: FileOutputStream 上代码 package com.demo ...
- CTFHub - Web(四)
最近又是每天忙到裂开,,,淦 xss: 反射型: 1.第一个输入框与下面Hello后的内容相同,猜测可以通过该输入,改变页面内容. 测试语句: <script>alert(1)</s ...
- 《进击吧!Blazor!》第一章 2.Hello Blazor
第二次写专栏,开头还是不知道说什么,所以--先来段广告<进击吧!Blazor!>是本人与张善友老师合作的Blazor零基础入门系列视频,此系列能让一个从未接触过Blazor的程序员掌握开发 ...
- Android 开发学习进程0.27 kotlin使用 和viewbinding的使用
kotlin-android-extensions 插件被废弃 笔者曾经尝试写过一部分的kotlin代码 主要是项目中一些代码是kotlin完成的,其中我认为 kotlin的kotlin-androi ...
- 提示框,对话框,路由跳转页面,跑马灯,幻灯片及list组件的应用
目录: 主页面的js业务逻辑层 主页面视图层 主页面css属性设置 跳转页面一的js业务逻辑层 跳转页面一的视图层 跳转页面二的视图层 跳转页面三的js业务逻辑层 跳转页面三的视图层 跳转页面三的cs ...
- Netty编解码器(理论部分)
背景知识 在了解Netty编解码之前,先回顾一下JAVA的编解码: 编码(Encode):在java中称之为序列化,把内存中易丢失的数据结构或对象状态转换成另一种可存储(存储到磁盘),可在网络间传输的 ...
- 基于final shell的linux命令
final shell操作教程: 1.查看API实时日志:cd ../../data/log/api tail -100f anyAPI-server.log2.关闭日志:control+c3.恢复实 ...
- hive 时间相关的函数
yyyy-MM-dd与yyyyMMdd000000转换的三种方法 方法一:date_format(只支持yyyy-MM-dd -> yyyyMMdd000000) select date_for ...
- websocket心跳重连 websocket-heartbeat-js
初探和实现websocket心跳重连(npm: websocket-heartbeat-js) 心跳重连缘由 websocket是前后端交互的长连接,前后端也都可能因为一些情况导致连接失效并且相互之间 ...