[bzoj1857] [Scoi2010]传送带

  三分套三分。

  如果只有一条线段和一个点的话显然三分。。两条线段的话大概就是三分套三分了吧(反正我不会证

实测eps取1e-3就行了。。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #define d double
 7 #define y1 y11
 8 using namespace std;
 9 const d eps=1e-3;
10 int i,j,k,n,m,a,b,c;
11 d x1,x2,y11,y2,lx,ly,rx,ry,ans;
12 int sx1,sx2,sy1,sy2,tx1,tx2,ty1,ty2;
13  
14 inline d dis(d x1,d y1,d x2,d y2){return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));}
15 inline d sum(d x1,d y1,d x2,d y2){
16     return dis((d)sx1,(d)sy1,x1,y1)/(d)a+dis(x1,y1,x2,y2)/(d)c+dis(x2,y2,(d)tx2,(d)ty2)/(d)b;
17 }
18 d get(d X,d Y){
19     d x1=tx1,x2=tx2,y1=ty1,y2=ty2,lx=x1,ly=y1,rx,ry,tim1,tim2,now=1002333333.0;
20     while(dis(x1,y1,x2,y2)>=eps){
21         lx=x1+(x2-x1)/3.0,ly=y1+(y2-y1)/3.0;
22         rx=lx+lx-x1,ry=ly+ly-y1;
23         tim1=sum(X,Y,lx,ly),tim2=sum(X,Y,rx,ry);
24          
25         if(tim1<tim2)x2=rx,y2=ry,now=min(now,tim1);
26         else x1=lx,y1=ly,now=min(now,tim2);
27     }
28     now=min(now,sum(X,Y,lx,ly));
29     ans=min(ans,now);
30     return now;
31 }
32  
33 int main(){
34     scanf("%d%d%d%d",&sx1,&sy1,&sx2,&sy2);
35     scanf("%d%d%d%d",&tx1,&ty1,&tx2,&ty2);
36     scanf("%d%d%d",&a,&b,&c);
37     ans=1002333333.0;
38      
39     x1=sx1,x2=sx2,y1=sy1,y2=sy2;
40     lx=x1,ly=y1;
41     while(dis(x1,y1,x2,y2)>=eps){
42         lx=x1+(x2-x1)/3.0,ly=y1+(y2-y1)/3.0;
43         rx=lx+lx-x1,ry=ly+ly-y1;
44         if(get(lx,ly)<get(rx,ry))x2=rx,y2=ry;
45         else x1=lx,y1=ly;
46     }
47     ans=min(ans,get(x1,y1));
48     printf("%.2lf\n",ans);
49     return 0;
50 }
View Code

(反正怎么写都不会TLE,所以具体处理写得有点龊

posted @ 2016-03-08 13:35  czllgzmzl  阅读(201)  评论(0编辑  收藏  举报