HDU/HDOJ 3400 Line belt 三分嵌套 杭电月赛
2011-08-05 10:09
591 查看
Line belt
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 24 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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?
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
Author
lxhgww&&momodi
Source
HDOJ Monthly Contest – 2010.05.01这个题思想很简单,就是三分重叠着用就是了
首先在AB上三分一个点出来,然后再在CD上三分一个点让值最小
两次三分重叠起来就可以解决题目了。。
先开始我的程序WA了好多次。一直不知道原因
后来查了下解题报告,发现他们说要再计算距离里面去加上一个精度
结果,果然就AC了。此题数据太YD了。。
另外,我三分的是距离A的距离和距离D的距离
我的代码:
#include<stdio.h> #include<math.h> #define eps 1e-9 struct point { double x; double y; }; point A,B,C,D,M1,M2; double P,Q,R; double dis(point a,point b) { return sqrt(eps+(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double cal2(double len) { double d1,d2,k,t1,t2; d1=len,d2=dis(C,D); k=d1/d2; M2.x=(C.x-D.x)*k+D.x; M2.y=(C.y-D.y)*k+D.y; t1=dis(M1,M2)/R; t2=len/Q; return (t1+t2); } double cal1(double len) { int i; double d1,d2,k,t1,tx,ty; d1=len,d2=dis(A,B); k=d1/d2; M1.x=(B.x-A.x)*k+A.x; M1.y=(B.y-A.y)*k+A.y; t1=len/P; double left,right,mid1,mid2; left=0,right=dis(C,D); for(i=1;i<=100;i++) { mid1=(2*left+right)/3; mid2=(left+2*right)/3; tx=cal2(mid1); ty=cal2(mid2); if(tx>ty) { left=mid1; } else { right=mid2; } } return t1+cal2(left); } void triple() { int i; double mid1,mid2,left,right,t1,t2; left=0,right=dis(A,B); for(i=1;i<=100;i++) { mid1=(left*2+right)/3; mid2=(left+2*right)/3; t1=cal1(mid1); t2=cal1(mid2); if(t1>t2) { left=mid1; } else { right=mid2; } } printf("%.2lf\n",cal1(left)); } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y); scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y); scanf("%lf%Lf%lf",&P,&Q,&R); triple(); } return 0; }
相关文章推荐
- hdoj 3400 Line belt (三分嵌套搜索 )
- HDU 3400 Line belt (三分嵌套)
- HDU 3400 Line belt(嵌套三分)
- HDU 3400 Line belt 嵌套三分搜索
- hdu 3400 Line belt【三分嵌套】
- hdu 3400 Line belt(多重三分)
- 杭电 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 双三分
- Line belt HDU - 3400 三分
- Hdu 3400 Line belt (三分)
- hdu 3400 Line belt 三分
- HDU 3400 Line belt 三分
- HDU 3400 Line belt (三分套三分)