hdu 3400 Line belt
来源:互联网 发布:vscode eclipse 编辑:程序博客网 时间:2024/05/17 18:45
Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3023 Accepted Submission(s): 1155
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?
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
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
10 0 0 100100 0 100 1002 2 1
Sample Output
136.60
Author
lxhgww&&momodi
- 分析:基本思想就时枚举线段AB,CD上所有点的组合,取最优解,在次基础上
- 用三分优化,至于为何用三分,是因为它是凸函数,在此不予证明。
- 献上代码:
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<iostream>
- #include<math.h>
- #define eps 1e-9
- using namespace std;
- double ax,ay,bx,by,cx,cy,dx,dy;
- double k1,l1,l2;
- double p,q,r1;
- double dis(double ax,double ay,double bx,double by)
- {
- return sqrt((bx-ax)*(bx-ax)+(by-ay)*(by-ay));
- }
- double cal(double k2)
- {
- double t1,t2,t3;
- t1=l1*k1/p;
- t2=l2*(1-k2)/q;
- t3=dis(ax+(bx-ax)*k1,ay+(by-ay)*k1,cx+(dx-cx)*k2,cy+(dy-cy)*k2)/r1;
- return t1+t2+t3;
- }
- double thr()
- {
- double l,r,mid,midmid,dis1,dis2;
- l=0,r=1;
- while(r-l>=eps)
- {
- mid=(l+r)/2;
- midmid=(mid+r)/2;
- dis1=cal(mid);
- dis2=cal(midmid);
- if(dis1<dis2)
- {
- r=midmid;
- }
- else
- {
- l=mid;
- }
- }
- return dis1<dis2?dis1:dis2;
- }
- int main()
- {
- int T;
- double l,r,mid,midmid,dis1,dis2;
- scanf("%d",&T);
- while(T--)
- {
- scanf("%lf%lf%lf%lf",&ax,&ay,&bx,&by);
- scanf("%lf%lf%lf%lf",&cx,&cy,&dx,&dy);
- scanf("%lf%lf%lf",&p,&q,&r1);
- l=0,r=1;
- l1=dis(ax,ay,bx,by);
- l2=dis(cx,cy,dx,dy);
- while(r-l>=eps)
- {
- mid=(l+r)/2;
- midmid=(mid+r)/2;
- k1=mid;
- dis1=thr();
- k1=midmid;
- dis2=thr();
- if(dis1<dis2)
- {
- r=midmid;
- }
- else
- {
- l=mid;
- }
- }
- printf("%.2lf\n",dis1<dis2?dis1:dis2);
- }
- return 0;
- }
0 0
- HDU 3400 Line belt
- HDU 3400 Line belt
- hdu 3400 Line belt
- HDU 3400 Line belt
- hdu 3400 Line belt
- hdu 3400 Line belt
- HDU 3400 Line belt
- HDU 3400 Line belt
- HDU 3400 Line belt
- hdu 3400 Line belt
- HDU 3400 Line belt 三分
- HDU OJ 3400 Line belt
- HDU 3400 Line belt (三分法)
- hdu 3400Line belt(三分法)
- HDU 3400 Line belt 三分
- HDU 3400 Line belt(三分)
- hdu 3400 Line belt 三分
- HDU 3400 Line belt 三分
- Find the least common multiple
- 交流与反思
- 图解classloader加载class的流程及自定义ClassLoader
- Socket网络编程
- 单线程信号
- hdu 3400 Line belt
- 如何在windows下安装GIT并部署项目到百度BAE
- SpringMVC数据验证--Validation
- inet_addr、inet_aton 、inet_network
- 抽象父类SqlHelper
- bootstrap第二篇
- github 易百,简单精确的解释
- Java web项目css引用项目图片解决办法
- Install KVM