Line belt HDU
来源:互联网 发布:js object 数组去重 编辑:程序博客网 时间:2024/06/17 13:24
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
平面上两条直线AB,CD,动点从A出发,在某点离开AB前往CD某点,再到达D点,各直线和平面上移动速度不同,求最少时间。
从AB哪点出发,和到达CD哪点都是需要查找的对象,所以要两次三分,先三分查找第一个点,再在该情况下找最优的第二个点。
#include <stdio.h>#include <math.h>int T,i,j;double s,p,q,r;struct node{ double x,y; node(int xx=0,int yy=0):x(xx),y(yy){}}a,b,c,d;double dis(node aa,node bb){ double re=sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y)); return re;}double sf2(node n){ double t1,t2; node low(c.x,c.y); node high(d.x,d.y); node m1,m2; do{ m1.x=(low.x+high.x)/2; m1.y=(low.y+high.y)/2; m2.x=(low.x+m1.x)/2; m2.y=(low.y+m1.y)/2; t1=dis(m1,d)/q+dis(n,m1)/r; t2=dis(m2,d)/q+dis(n,m2)/r; if(t1<t2){ low.x=m2.x; low.y=m2.y; }else{ high.x=m1.x; high.y=m1.y; } }while(dis(low,high)>1e-8); return t1;}double sf1(){ double t1,t2; node low(a.x,a.y); node high(b.x,b.y); node m1,m2; do{ m1.x=(low.x+high.x)/2; m1.y=(low.y+high.y)/2; m2.x=(low.x+m1.x)/2; m2.y=(low.y+m1.y)/2; t1=sf2(m1)+dis(m1,a)/p; t2=sf2(m2)+dis(m2,a)/p; if(t1<t2){ low.x=m2.x; low.y=m2.y; }else{ high.x=m1.x; high.y=m1.y; } }while(dis(low,high)>1e-8); return t1;}int main(){ 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("%lf%lf%lf",&p,&q,&r); s=sf1(); printf("%.2lf\n",s); } return 0;}
- HDU 3400 Line belt
- HDU 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 3700 Line belt
- HDU 3400 Line belt
- HDU 3400 Line belt
- Line belt HDU
- hdu 3400 Line belt
- Line belt HDU
- HDU 3400 Line belt 三分
- HDU OJ 3400 Line belt
- HDU 3400 Line belt (三分法)
- hdu 3400Line belt(三分法)
- HDU4704_Sum_加隔板问题&&费马小定理
- SMB实现共享文件(上传、下载)
- Android中aCache缓存机制详解
- Android性能优化之内存优化
- STM32 BOOT模式配置以及作用
- Line belt HDU
- 数据结构与算法分析(Java语言描述)(4)—— 希尔排序
- 微信APP支付常见开发问题解答
- Map
- PHP反序列化漏洞学习总结
- 获取和设置环境变量函数
- 17.11.2日报
- 天生爱分享
- 此生无悔入联盟,来世愿生峡谷中