Problem Description
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.
Input
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.
Output
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)
Sample Input
#
# #
# #
#
#
#
Sample Output
1.03
0.00
No Answer
Source
三维数组标记消耗的体力,如果if(vis[t2.x][t2.y][t2.t]>t2.v) 则继续入队。
#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 ;
}