2016SDAU编程练习二1006

Line belt 


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.<br>How long must he take to travel from A to D?
 


Input
The first line is the case number T.<br>For each case, there are three lines.<br>The first line, four integers, the coordinates of A and B: Ax Ay Bx By.<br>The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.<br>The third line, three integers, P Q R.<br>0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000<br>1<=P,Q,R<=10
 


Output
The minimum time to travel from A to D, round to two decimals.
 


Sample Input
1<br>0 0 0 100<br>100 0 100 100<br>2 2 1 


Sample Output
136.60 


Author
lxhgww&&momodi
 


Source
HDOJ Monthly Contest – 2010.05.01

 

题意:给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度,求a到d点的最短时间

思路:三分法,就是给了两条线段,每条中必定有一点,连接后时间最短

感想:这个就比较复杂一点了

AC代码

#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
double p,q,R;
struct point
{
    double x;
    double y;
    point operator / (const point &others)
    {
        point tt;
        tt.x=(this->x+others.x)/2;
        tt.y=(this->y+others.y)/2;
        return tt;
    }
};
double length (point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find ( point c,point d,point mid )
{
    point l,r,mid1,mid2;
    double t1,t2;
    l=c;r=d;
    do
    {
        mid1=(r/l);
        mid2=(r/mid1);
        t1=length(mid1,d)/q+length(mid1,mid)/R;
        t2=length(mid2,d)/q+length(mid2,mid)/R;
        if(t1>t2)
            l=mid1;
        else
            r=mid2;
    }while(fabs(t1-t2)>0.00001);
    return t2;
}
int main()
{
   // freopen("r.txt","r",stdin);
    int N;
    point a,b,c,d,r,l,mid1,mid2;
    double t1,t2;
    cin>>N;
    while(N--)
    {
        cin>>a.x>>a.y>>b.x>>b.y;
        cin>>c.x>>c.y>>d.x>>d.y;
        cin>>p>>q>>R;
        l=a;r=b;
        do
        {
            mid1=(r/l);
            mid2=(r/mid1);
            t1=length(a,mid1)/p+find(c,d,mid1);
            t2=length(a,mid2)/p+find(c,d,mid2);
            if(t1>t2)
                l=mid1;
            else
                r=mid2;
        }while(fabs(t2-t1)>0.00001);
        printf("%.2f\n",t2);


    }
    return 0;




}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值