三分的入门题,如果从AB上一点走到D是一个单峰函数
从AB开始向CD传送带走的那个点也是一个单峰函数
显然三分套三分

const eps=1e-5;
var ax,ay,bx,by,cx,cy,dx,dy,p,q,v:longint;
    l,r,m:double;

function calc(r1,r2:double):double;
  var s1,s2,s3,x1,x2,y1,y2:double;
  begin
    x1:=ax+(bx-ax)*r1;
    y1:=ay+(by-ay)*r1;
    x2:=cx+(dx-cx)*r2;
    y2:=cy+(dy-cy)*r2;
    s1:=sqrt(sqr(x1-ax)+sqr(y1-ay));
    s2:=sqrt(sqr(dx-x2)+sqr(dy-y2));
    s3:=sqrt(sqr(x1-x2)+sqr(y1-y2));
    exit(s1/p+s2/q+s3/v);
  end;

function work(x:double):double;
  var l,r,m:double;
  begin
    l:=0;
    r:=1;
    while l+eps<r do
    begin
      m:=(r-l)/3;
      if calc(x,l+m)>calc(x,r-m) then l:=l+m
      else r:=r-m;
    end;
    exit(calc(x,l));
  end;

begin
  readln(ax,ay,bx,by);
  readln(cx,cy,dx,dy);
  readln(p,q,v);
  l:=0;
  r:=1;
  while l+eps<r do  //三分精度
  begin
    m:=(r-l)/3;
    if work(l+m)>work(r-m) then l:=l+m
    else r:=r-m;
  end;
  writeln(work(l):0:2);
end.
View Code

 

posted on 2015-04-10 14:17  acphile  阅读(152)  评论(0编辑  收藏  举报