智能車比賽


(NOI2011 智能車比賽)


program car;
const inf=1e49;
type node=record x,y:longint; end;
operator -(a:node;b:node)c:node;begin c.x:=a.x-b.x; c.y:=a.y-b.y; end;
operator *(a:node;b:node)c:double;begin c:=a.y*b.x-b.y*a.x; end;
operator +(a:node;b:node)c:double;begin c:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); end;
function g(d:double):double; begin g:=d; if abs(d)<=1e-5 then exit(0);end;
function min(i:double;j:double):double;begin if i<j then exit(i);exit(j);end;
var a:array[1..4100]of record u,d:node;end; d:array[1..4100,0..1]of double;
    _S,_T:node; ans,_v:double; n,ds,dt,i:longint;
procedure init;var i,t,x1,x2,y1,y2:longint; tt:node;
begin
    readln(n);t:=0;ans:=inf;
    for i:=1 to n<<1 do begin d[i,0]:=inf; d[i,1]:=inf; end;
    for i:=1 to n do begin
    readln(x1,y1,x2,y2);
    inc(t);
    a[t].d.x:=x1;a[t].d.y:=y1;
    a[t].u.x:=x1;a[t].u.y:=y2;
    inc(t);
    a[t].d.x:=x2;a[t].d.y:=y1;
    a[t].u.x:=x2;a[t].u.y:=y2;
    end;
    readln(_S.x,_S.y);readln(_T.x,_T.y);
    if _s.x>_t.x then begin tt:=_s;_s:=_t;_t:=tt;end;
    ds:=1 ;  while (a[ds].u.x<_s.x) do inc(ds);
    if a[ds].u.x=_s.x then if (a[ds].u.y<_s.y)or(a[ds].d.y>_s.y) then inc(ds);    
    dt:=n<<1;while (a[dt].u.x>_t.x) do dec(dt);
    if a[dt].u.x=_t.x then if (a[dt].u.y<_t.y)or(a[dt].d.y>_t.y) then dec(dt);
    readln(_v);
end;
procedure expand(s:node;i:longint;dd:double);
var up:node=(x:0;y:1);dn:node=(x:0;y:-1);
begin
    for i:=i to dt do begin
    if (g(up*(a[i].u-s))>=0) then begin up:=a[i].u-s;
    if (g((a[i].u-s)*dn)>=0) then d[i,1]:=min(d[i,1],dd+(a[i].u+s)); end;
    if (g((a[i].d-s)*dn)>=0) then begin dn:=a[i].d-s;
    if (g(up*(a[i].d-s))>=0) then d[i,0]:=min(d[i,0],dd+(a[i].d+s));end;
    if g(up*dn)<0 then break;
    end;
    if (up*(_t-s)>=0)and(dn*(_t-s)<=0) then ans:=min(ans,dd+(s+_t));
end;
begin
    init;expand(_s,ds,0);
    for i:=ds to dt do begin
    if d[i,1]<inf then expand(a[i].u,i+1,d[i,1]);
    if d[i,0]<inf then expand(a[i].d,i+1,d[i,0]);
    end;writeln(ans/_v:0:10); 
end.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章