Problem Description
In a
two-dimensional plane there are two line belts, there are two
segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he
can move with the speed R on other area on the plane.

How long must he take to travel from A to D?
Input
The first line
is the case number T.

For each case, there are three lines.

The first line, four integers, the coordinates of A and B: Ax Ay Bx
By.

The second line , four integers, the coordinates of C and D:Cx Cy
Dx Dy.

The third line, three integers, P Q R.

0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000

1<=P,Q,R<=10
Output
The minimum
time to travel from A to D, round to two decimals.
Sample Input
1
0 0 0
100
100 0
100
100 2 2
1
Sample Output
136.60
题意:有两个传送带,由A到B的速度是p,有C到D的速度是q,其他速度是r,求由A到D的最少时间;如图(原创)
解题思路:在A,B之间去mid,然后三分求最小时间,三分过程中是A到mid的时间加上mid到D的时间(mid到D的时间,也用三分求,最好写一个函数,求A到mid的时间用三分时,每计算一次,都得在当前状态求一个mid到D的时间),然后就能得出来最小时间;
感悟:思路不好想;刚开始想的是,在AB中去mid先求出最合适的mid到D的时间,然后把B转移到mid,然后再在CD上取mid,求最合适的mid;这样不是动态中求得,不行。
思路不好写,代码更不好写啊,用do,while能过,用while就过不了;
代码:
#include

#include

#include

#include

#include

using namespace std;

const double eps=1e-6;





struct coordinate

{

    double
x;

    double
y;

};

coordinate A,B,C,D;

int t;

double p,q,r;

double dis(coordinate a,coordinate b)

{

    double
t;

   
t=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

   
//printf("t=%.2f\n",t);

    return
t;

}//求两点之间的距离

coordinate midc(coordinate a,coordinate b)

{

    coordinate
t;

   
t.x=(a.x+b.x)*0.5;

   
t.y=(a.y+b.y)*0.5;

    return
t;

}//求坐标的中点

double time(coordinate a,coordinate b,coordinate c,coordinate
d)

{

    double
t;

   
t=dis(a,b)/p+dis(b,c)/r+dis(c,d)/q;

   
//printf("t=%.2f\n",t);

    return
t;

}//求路径的总时间

double Three_algorithm_1(coordinate a,coordinate c,coordinate
d)

{

    double
t1,t2;

    coordinate
left,right,mid,midmid;

   
left=c;

   
right=d;

    do

    {

       
mid=midc(left,right);

       
midmid=midc(mid,right);

      
// printf("dis(right,left)=%.5f\n",dis(right,left));

       
t1=dis(a,mid)/r+dis(mid,d)/q;

       
t2=dis(a,midmid)/r+dis(midmid,d)/q;

       
if(t1>t2)left=mid;

       
else right=midmid;

   
}while(dis(right,left)>=eps);

    return
t1;

}//先求出A到CD段的最小时间

double Three_algorithm_2(coordinate a,coordinate b,coordinate
c,coordinate d)

{

    double
t1,t2;

    coordinate
left,right,mid,midmid;

   
left=a;

   
right=b;

   
mid=midc(left,right);

   
midmid=midc(mid,right);

    do

    {

       
mid=midc(left,right);

       
midmid=midc(mid,right);

       
//printf("dis(right,left)=%.f\n",dis(right,left));

       
t1=dis(a,mid)/p+Three_algorithm_1(mid,c,d);

       
t2=dis(a,midmid)/p+Three_algorithm_1(midmid,c,d);

       
if(t1>t2)left=mid;

       
else right=midmid;

   
}while(dis(right,left)>=eps);

    return
t1;

}//加上前面求出的先求出A到CD段的最小时间,用三分求最少时间

int main()

{

   
//freopen("in.txt", "r", stdin);

   
scanf("%d",&t);

    for(int
i=0;i

    {

       
scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);

       
scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y);

       
scanf("%lf%lf%lf",&p,&q,&r);

       
printf("%.2lf\n",Three_algorithm_2(A,B,C,D));

    }

}

Line belt的更多相关文章

  1. 三分套三分 --- HDU 3400 Line belt

    Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...

  2. 搜索(三分):HDU 3400 Line belt

    Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 3400 Line belt (三分嵌套)

    题目链接 Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. HDU 3400 Line belt (三分再三分)

    HDU 3400 Line belt (三分再三分) ACM 题目地址:  pid=3400" target="_blank" style="color:rgb ...

  5. Line belt(三分镶嵌)

    In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's spee ...

  6. HDU 3400 Line belt【三分套三分】

    从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间   f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间   ...

  7. hdu Line belt

    这道题是一道3分搜索的题.其实这种题很多时候都出现在高中的解析几何上,思路很简单,从图中可以看到,肯定在AB线段和CD线段上各存在一点x和y使得所花时间最少 因为AB和CD上的时间与x和y点的坐标都存 ...

  8. hdu 3400 Line belt 三分法

    思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...

  9. hdu 3400 Line belt

    题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...

随机推荐

  1. go-fasthttp源码分析

    1.架构 listener->server->workerpool 1.1.workerpool中有两种缓存: a.wp.ready,缓存未退出worker, b.worker退出后用sy ...

  2. [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线,弧线,圆形)

    绘制曲线,经常会用到路径的知识,如果你对路径有疑问,可以参考我的这篇文章[js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解. arc:画 ...

  3. program 1 : python codes for login program(登录程序python代码)

    #improt time module for count down puase time import time #set var for loop counting counter=1 #logi ...

  4. 三、js的函数

    三.函数 函数是定义一次但却可以调用或执行任意多次的一段JS代码.函数有时会有参数,即函数被调用时指定了值的局部变量.函数常常使用这些参数来计算一个返回值,这个值也成为函数调用表达式的值. 1.函数声 ...

  5. Query DSL(2)----Full text queries

    Match Query match查询接受文本/数值/日期 { "match" : { "message" : "this is a test&quo ...

  6. Bmob云IM实现头像更换并存入Bmob云数据库中(1.拍照替换,2.相册选择)

    看图效果如下: 1.个人资料界面 2.点击头像弹出对话框 3.点击拍照 4.切割图片,选择合适的部分 5.点击保存,头像替换完毕,下面看从相册中选择图片. 6.点击相册 7.任选一张图片 8.切割图片 ...

  7. String+ String.Concat String.Format StringBuilder 之间的性能测试

    找到一篇国外的代码,专门来测试这个, String+ String.Concat String.Format StringBuilder 前三个在100个左右字符串差不多, String.Concat ...

  8. Promise 对象

    Promise 对象用于处理异步请求,保存一个异步操作最终完成(或失败)的结果 语法 new Promise( /* executor */ function(resolve, reject) {.. ...

  9. sqlserver游标使用和循环

    /*** 游标的使用 讲了这个多游标的优点,现在我们就亲自来揭开游标的神秘的面纱. 使用游标的顺序: 声名游标.打开游标.读取数据.关闭游标.删除游标. 1.3.1声明游标 最简单游标声明:DECLA ...

  10. hadoop streaming编程小demo(python版)

    大数据团队搞数据质量评测.自动化质检和监控平台是用django,MR也是通过python实现的.(后来发现有orc压缩问题,python不知道怎么解决,正在改成java版本) 这里展示一个python ...