SDAU2 课程练习2 1006

Line belt

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 31   Accepted Submission(s) : 7
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


题目大意:

给出  A B C D 四个点坐标,给出 p  q  v ,三个速度,质点 在A B 上运动速度为 p  在 C D 上速度为 q  ,其他地方速度为  v  。求A 到 D 最短时间。


思路:


路线一定是 这样的。 从  A开始 到 AB  上的  o 点,再到 cd  上的 n  点,最后到达  D  。  其中Ao  nD  都可以为 0 。


列出表达式  Ao / p + on /v +nD/q

首先在AB'上 找出一个点,再三分在 CD上找出此时的最短时间点。重复此过程。也就是说在  AB上三分,再在  CD 上三分。

最终求出最短时间。


感想:


三分嵌套三分,这个想法也不怎么好想出来,参考了别人的博客。


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;


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值