HDU 3400(搜索题,三分~~初识三分查找)
2010-07-28 12:43
381 查看
Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 698 Accepted Submission(s): 243
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 先对AB段三分一次,在对CD三分一次。。。一直循环#include <iostream> #include <math.h> using namespace std; #define EPS 1e-10 struct point { double x,y; }; point A,B,C,D,aa,bb,low1,high1,low2,high2,mid1,mid2,mid3,mid4; double P,Q,R; double lenth(point a,point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } bool judge1(point x1,point x2) { if((lenth(A,x1)/P+lenth(x1,bb)/R+lenth(bb,D)/Q)>=(lenth(A,x2)/P+lenth(x2,bb)/R+lenth(bb,D)/Q)) return true; else return false; } bool judge2(point x1,point x2) { if((lenth(A,aa)/P+lenth(aa,x1)/R+lenth(x1,D)/Q)>=(lenth(A,aa)/P+lenth(aa,x2)/R+lenth(x2,D)/Q)) return true; else return false; } void san_fen1(); void san_fen2(); int main() { int t; while(scanf("%d",&t)!=EOF) { 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); aa=A; bb=D; low1=A; high1=B; low2=C; high2=D; if(R>=P && R>=Q) { printf("%.2lf/n",lenth(A,D)/R); continue; } san_fen1(); printf("%.2lf/n",lenth(A,low1)/P+lenth(low1,low2)/R+lenth(low2,D)/Q); } } return 0; } void san_fen1() { while (lenth(low1,high1)>EPS) { mid1.x=(2*low1.x+high1.x)/3; mid1.y=(2*low1.y+high1.y)/3; mid2.x=(low1.x+2*high1.x)/3; mid2.y=(low1.y+2*high1.y)/3; if(judge1(mid1,mid2)) low1=mid1; else high1=mid2; aa.x=(low1.x+high1.x)/2; aa.y=(low1.y+high1.y)/2; san_fen2(); } while (lenth(low2,high2)>EPS) { mid3.x=(2*low2.x+high2.x)/3; mid3.y=(2*low2.y+high2.y)/3; mid4.x=(low2.x+2*high2.x)/3; mid4.y=(low2.y+2*high2.y)/3; if(judge2(mid3,mid4)) low2=mid3; else high2=mid4; bb.x=(low2.x+high2.x)/2; bb.y=(low2.y+high2.y)/2; } } void san_fen2() { if (lenth(low2,high2)>EPS) { mid3.x=(2*low2.x+high2.x)/3; mid3.y=(2*low2.y+high2.y)/3; mid4.x=(low2.x+2*high2.x)/3; mid4.y=(low2.y+2*high2.y)/3; if(judge2(mid3,mid4)) low2=mid3; else high2=mid4; bb.x=(low2.x+high2.x)/2; bb.y=(low2.y+high2.y)/2; } }
相关文章推荐
- 搜索(三分):HDU 3400 Line belt
- HDU 3400 Line belt (三分搜索)
- HDU 3400 Line belt 嵌套三分搜索
- HDU 3400 Line belt (三分再三分)
- Party All the Time+hdu+三分搜索
- hdu 3400 Line belt(多重三分)
- 【三分】hdu 3400
- hdu 3400 悲剧的三分
- HDU 4717 The Moving Points (三分搜索)
- The Moving Points HDU - 4717 (三分查找)
- HDU-2899(三分搜索)
- HDU 3400 Line belt (三分套三分)
- hdu 3400 Line belt 三分
- HDU 3714 - Error Curves (三分查找)
- HDU 3400 (三分)
- YT14-HDU-三分查找求F(x)的最小值
- HDU 3400 两次三分
- hdu 2438+hdu 3400(三分求极值)
- HDU 3400 Line belt 三分
- hdu 3400 Line belt(三分套三分)