bzoj2709

http://www.lydsy.com/JudgeOnline/problem.php?id=2709


可以看出s到e的最短路关于v单调不减

二分v做最短路好了

注意精度,要卡到1e-7



program bzoj2709;
const
    eps=1e-7;
    zl:array [1..4,1..2] of longint=((1,0),(-1,0),(0,1),(0,-1));
var
	p,l,v,s,e:double;
    t,x,y,tot,sx,sy,ex,ey,r,c,i,j,k:longint;
    dis:array [0..101,0..101] of double;
    map:array [0..101,0..101] of char;
    dl:array [0..1000001] of record
                                        x,y:longint;
                                        end;

begin
    readln(t);
    while t>0 do
        begin
            dec(t);
            readln(l,r,c);
            for i:=0 to r+1 do
                for j:=0 to c+1 do
                    map[i,j]:='#';
            for i:=1 to r do
                begin   
                    for j:=1 to c do
                        begin
                            read(map[i,j]);
                            if map[i,j]='S' then
                                begin
                                    sx:=i;
                                    sy:=j;
                                end;
                            if map[i,j]='E' then
                                begin
                                    ex:=i;
                                    ey:=j;
                                end;
                        end;
                    readln;
                end;
            s:=0;
            e:=10;
            while abs(s-e)>eps do
                begin
                    v:=(s+e)/2;
                    fillchar(dis,sizeof(dis),87);
                    dl[0].x:=sx;
                    dl[0].y:=sy;
                    tot:=0;
                    dis[sx,sy]:=0;
                    i:=0;
                    while i<=tot do
                        begin
                            for j:=1 to 4 do
                                begin
                                    if j<=2 then p:=v
                                                else p:=1;
                                    x:=dl[i].x+zl[j,1];
                                    y:=dl[i].y+zl[j,2];
                                    if (map[x,y]<>'#')and(dis[x,y]>dis[dl[i].x,dl[i].y]+p) then
                                        begin
                                            dis[x,y]:=dis[dl[i].x,dl[i].y]+p;
                                            inc(tot);
                                            dl[tot].x:=x;
                                            dl[tot].y:=y;
                                        end;
                                end;
                            inc(i);
                        end;
                    if dis[ex,ey]<l then s:=v
                                        else e:=v;
                end;
            writeln(s:0:5);
        end;
end.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值