Description
Bessie和其他一些人去滑雪。Bessie发现她自己站在一块R*C(1<=R,C<=100)的区域中,区域中的每一块都有一个高度值E_ij(-25<=E_ij<=25)。为了参加大家的聚会,Bessie想要尽快到达右下角。Bessie每一步只能向正东,正西,正南,正北前进一步。Bessie以初速度V(1<=V<=1,000,000)前进,她发现了一个她的速度和高度的关系。当Bessie从高度A移动到高度B时,他的速度就乘上了一个数2^(A-B)。Bessie移动一步的速度取决于她在前一格时的速度。
请找出Bessie移动所需的最小时间。
Input
第1行:3个用空格隔开的整数:V,R,C,分别表示Bessie的初速度和区域的长度和宽度
第2 - R+1行:以矩阵的形式表示该区域中各块的高度。
Output
输出一个实数(保留2位小数),表示Bessie达到目的地最少需要的时间。
Sample Input
1 3 3
1 5 3
6 3 5
2 4 3
Sample Output
29.00
Data Constraint
Hint
【样例说明】
Bessie的最佳路径是:
(1,1) 时间 0 速度 1
(1,2) 时间 1 速度 1/16
(2,2) 时间 17 速度1/4
(3,2) 时间 21 速度1/8
(3,3) 时间 29 速度 1/4
.
.
.
.
.
.
分析
bfs
注意精度!!!!!!!!!!!!
.
.
.
.
.
.
.
程序:
const
px:array[1..4]of longint=(0,0,1,-1);
py:array[1..4]of longint=(1,-1,0,0);
var
i,j,l,r,c,v,x,y:longint;
a:array[0..105,0..105]of longint;
s:array[0..1000005,1..2]of longint;
t:array[0..1000005]of double;
f:array[0..105,0..105]of double;
bz:array[0..105,0..105]of boolean;
w:array[-50..50]of double;
ans:double;
function check(x,y:longint):boolean;
begin
if (x=0)or(y=0)or(x>r)or(y>c) then exit(true);
exit(false);
end;
procedure bfs;
begin
f[1,1]:=0;
s[1,1]:=1;s[1,2]:=1;
t[1]:=v;
i:=0;j:=1;
while i<>j do
begin
i:=(i mod 1000001)+1;
for l:=1 to 4 do
begin
x:=s[i,1]+px[l];
y:=s[i,2]+py[l];
if check(x,y) then continue;
if 1/t[i]+f[s[i,1],s[i,2]]<f[x,y] then
begin
f[x,y]:=1/t[i]+f[s[i,1],s[i,2]];
ans:=t[i]*(w[a[s[i,1],s[i,2]]-a[x,y]]);
j:=(j mod 1000001)+1;
s[j,1]:=x;
s[j,2]:=y;
t[j]:=ans;
end;
end;
end;
end;
begin
assign(input,'cowski.in');
reset(input);
assign(output,'cowski.out');
rewrite(output);
readln(v,r,c);
for i:=1 to r do
begin
for j:=1 to c do
read(a[i,j]);
readln;
end;
w[0]:=1;
for i:=-1 downto -50 do
w[i]:=w[i+1]/2;
for i:=1 to 50 do
w[i]:=w[i-1]*2;
fillchar(f,sizeof(f),127);
bfs;
write(abs((f[r,c]-5.51*1e-11)):0:2);
close(input);
close(output);
end.