1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| const eps=1e-9; var xl,xr,yd,yu,dis,dx,dy:array[0..8010] of extended; n:longint; function getcut(sx,sy,ex,ey,x:extended):extended; begin exit((ey-sy)/(ex-sx)*(x-sx)+sy); end; function checkline(sx,sy,ex,ey:extended):boolean; var i:longint; y:extended; begin if abs(sx-ex)<eps then exit(true); for i:=1 to n do if (xl[i]+eps<=sx)and(ex+eps<=xr[i]) then exit(true) else if (sx<=xl[i]+eps)and(xr[i]<=ex+eps) then begin y:=getcut(sx,sy,ex,ey,xl[i]); if not((yd[i]<=y+eps)and(y<=yu[i]+eps)) then exit(false); y:=getcut(sx,sy,ex,ey,xr[i]); if not((yd[i]<=y+eps)and(y<=yu[i]+eps)) then exit(false); end else if (xl[i]<=sx+eps)and(sx+eps<=xr[i]) then begin y:=getcut(sx,sy,ex,ey,xr[i]); if not((yd[i]<=y+eps)and(y<=yu[i]+eps)) then exit(false); end else if (xl[i]+eps<=ex)and(ex<=xr[i]+eps) then begin y:=getcut(sx,sy,ex,ey,xl[i]); if not((yd[i]<=y+eps)and(y<=yu[i]+eps)) then exit(false); end; exit(true); end; procedure upd(var a:extended; const b:extended); begin if b<a then a:=b; end; function av(l,r,x:extended):boolean; begin exit((l<=x+eps)and(x<=r+eps)); end; procedure lemon(); var i,j:longint; sx,sy,ex,ey,v,x1,x2,l,r,_d,_x,_y,ans:extended; begin readln(n); for i:=1 to n do readln(xl[i],yd[i],xr[i],yu[i]); readln(sx,sy); readln(ex,ey); readln(v); if checkline(sx,sy,ex,ey) then begin writeln(sqrt(sqr(sx-ex)+sqr(sy-ey))/v:0:10); exit; end; for i:=5 to 4*n+4 do dis[i]:=1e100; for i:=1 to n do begin if checkline(sx,sy,xl[i],yd[i]) then dis[i*4+1]:=sqrt(sqr(sx-xl[i])+sqr(sy-yd[i])); if checkline(sx,sy,xl[i],yu[i]) then dis[i*4+2]:=sqrt(sqr(sx-xl[i])+sqr(sy-yu[i])); if checkline(sx,sy,xr[i],yd[i]) then dis[i*4+3]:=sqrt(sqr(sx-xr[i])+sqr(sy-yd[i])); if checkline(sx,sy,xr[i],yu[i]) then dis[i*4+4]:=sqrt(sqr(sx-xr[i])+sqr(sy-yu[i])); end; for i:=1 to n do begin _d:=dis[i*4+1]; _x:=xl[i]; _y:=yd[i]; l:=0; r:=(yu[i]-_y)/(xr[i]-_x); upd(dis[i*4+3],_d+xr[i]-_x); upd(dis[i*4+4],_d+sqrt(sqr(xr[i]-_x)+sqr(yu[i]-_y))); for j:=i+1 to n do begin x1:=(yd[j]-_y)/(xl[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xl[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+1],_d+sqrt(sqr(xl[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+2],_d+sqrt(sqr(xl[j]-_x)+sqr(yu[j]-_y))); x1:=(yd[j]-_y)/(xr[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xr[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+3],_d+sqrt(sqr(xr[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+4],_d+sqrt(sqr(xr[j]-_x)+sqr(yu[j]-_y))); if l>r+eps then break; end; _d:=dis[i*4+2]; _x:=xl[i]; _y:=yu[i]; l:=(yd[i]-_y)/(xr[i]-_x); r:=0; upd(dis[i*4+4],_d+xr[i]-_x); upd(dis[i*4+3],_d+sqrt(sqr(xr[i]-_x)+sqr(yd[i]-_y))); for j:=i+1 to n do begin x1:=(yd[j]-_y)/(xl[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xl[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+1],_d+sqrt(sqr(xl[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+2],_d+sqrt(sqr(xl[j]-_x)+sqr(yu[j]-_y))); x1:=(yd[j]-_y)/(xr[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xr[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+3],_d+sqrt(sqr(xr[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+4],_d+sqrt(sqr(xr[j]-_x)+sqr(yu[j]-_y))); if l>r+eps then break; end; _d:=dis[i*4+3]; _x:=xr[i]; _y:=yd[i]; if (i<>n)and(av(yd[i+1],yu[i+1],_y)) then begin l:=(yd[i+1]-_y)/(xr[i+1]-_x); r:=(yu[i+1]-_y)/(xr[i+1]-_x); upd(dis[i*4+7],_d+sqrt(sqr(xr[i+1]-_x)+sqr(yd[i+1]-_y))); upd(dis[i*4+8],_d+sqrt(sqr(xr[i+1]-_x)+sqr(yu[i+1]-_y))); for j:=i+2 to n do begin x1:=(yd[j]-_y)/(xl[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xl[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+1],_d+sqrt(sqr(xl[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+2],_d+sqrt(sqr(xl[j]-_x)+sqr(yu[j]-_y))); x1:=(yd[j]-_y)/(xr[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xr[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+3],_d+sqrt(sqr(xr[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+4],_d+sqrt(sqr(xr[j]-_x)+sqr(yu[j]-_y))); if l>r+eps then break; end; end; _d:=dis[i*4+4]; _x:=xr[i]; _y:=yu[i]; if (i<>n)and(av(yd[i+1],yu[i+1],_y)) then begin l:=(yd[i+1]-_y)/(xr[i+1]-_x); r:=(yu[i+1]-_y)/(xr[i+1]-_x); upd(dis[i*4+7],_d+sqrt(sqr(xr[i+1]-_x)+sqr(yd[i+1]-_y))); upd(dis[i*4+8],_d+sqrt(sqr(xr[i+1]-_x)+sqr(yu[i+1]-_y))); for j:=i+2 to n do begin x1:=(yd[j]-_y)/(xl[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xl[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+1],_d+sqrt(sqr(xl[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+2],_d+sqrt(sqr(xl[j]-_x)+sqr(yu[j]-_y))); x1:=(yd[j]-_y)/(xr[j]-_x); if x1>l then l:=x1; x2:=(yu[j]-_y)/(xr[j]-_x); if x2<r then r:=x2; if av(l,r,x1) then upd(dis[j*4+3],_d+sqrt(sqr(xr[j]-_x)+sqr(yd[j]-_y))); if av(l,r,x2) then upd(dis[j*4+4],_d+sqrt(sqr(xr[j]-_x)+sqr(yu[j]-_y))); if l>r+eps then break; end; end; end;
ans:=1e100; for i:=1 to n do begin if checkline(xl[i],yd[i],ex,ey) then upd(ans,dis[i*4+1]+sqrt(sqr(ex-xl[i])+sqr(ey-yd[i]))); if checkline(xl[i],yu[i],ex,ey) then upd(ans,dis[i*4+2]+sqrt(sqr(ex-xl[i])+sqr(ey-yu[i]))); if checkline(xr[i],yd[i],ex,ey) then upd(ans,dis[i*4+3]+sqrt(sqr(ex-xr[i])+sqr(ey-yd[i]))); if checkline(xr[i],yu[i],ex,ey) then upd(ans,dis[i*4+4]+sqrt(sqr(ex-xr[i])+sqr(ey-yu[i]))); end; writeln(ans/v:0:10); end; begin assign(input,'car.in'); reset(input); lemon(); end.
|