1006 of search

来源:互联网 发布:未成年犯罪知乎 编辑:程序博客网 时间:2024/06/06 18:48

Line belt

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 50   Accepted Submission(s) : 13
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
 题目大意:给你两条传送带的坐标和其上面的速度,还有传送带外的速度,求出物体从一条传送带起点到另一条重点的最短时间。
题目思路:1这是这个专题里三分的最难的题了,因为用了两次三分,每次在起始传送带上固定一点用三分找到最小时间,在继续三分找到这些最短时间中时间最少的。
             2由于起那几道题都可以用数学解决,这道我也试着用数学进行推倒,可惜水平有限,只是写出了满足的表达式,需要用到高维的线性规划知识,但目前并不知道怎么解。。。。
#include <iostream>#include <stdio.h>#include <math.h>using namespace std; struct point{    double x,y;};int p,q,r,v;double dis(point a,point b){    return pow(pow(a.y-b.y,2)+pow(a.x-b.x,2),1.0/2);}double findy(point c,point d,point y){    point mid,midmid,left,right;    double t1,t2;    left = c;    right = d;    do    {        mid.x = (left.x+right.x)/2;        mid.y = (left.y+right.y)/2;        midmid.x = (right.x+mid.x)/2;        midmid.y = (right.y+mid.y)/2;        t1 = dis(d,mid)/q+dis(mid,y)/r;        t2 = dis(d,midmid)/q+dis(midmid,y)/r;        if(t1>t2)        left = mid;        else right = midmid;    }while(fabs(t1-t2)>0.000001);    return t1;}double find(point a,point b,point c,point d){    point mid,midmid,left,right;    double t1,t2;    left = a;    right = b;    do    {        mid.x = (left.x+right.x)/2;        mid.y = (left.y+right.y)/2;        midmid.x = (right.x+mid.x)/2;        midmid.y = (right.y+mid.y)/2;        t1 = dis(a,mid)/p+findy(c,d,mid);        t2 = dis(a,midmid)/p+findy(c,d,midmid);        if(t1>t2)left = mid;        else right = midmid;    }while(fabs(t1-t2)>0.000001);    return t1;}int main(){    int t;    point a,b,c,d;    scanf("%d",&t);    while(t--)    {        scanf("%lf%lf%lf%lf %lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);        scanf("%d%d%d",&p,&q,&r);        printf("%.2f\n",find(a,b,c,d));    }    return 0;}



0 0
原创粉丝点击