HDU 3400 Line belt (三分搜索)
2013-09-30 07:32
489 查看
Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2329 Accepted Submission(s): 880
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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
[align=left]Output[/align]
The minimum time to travel from A to D, round to two decimals.
[align=left]Sample Input[/align]
1 0 0 0 100 100 0 100 100 2 2 1
[align=left]Sample Output[/align]
136.60
[align=left]Author[/align]
lxhgww&&momodi
[align=left]Source[/align]
HDOJ Monthly Contest – 2010.05.01
[align=left]Recommend[/align]
lcy
题意:
给你一个平面,平面上有两条线段AB和CD,某东西在AB上跑的速度是P,在CD上跑的速度是Q,在平面其他地方跑的速度是R,问从A点到D点的最快时间。
思路:
嵌套的三分搜索
1.首先明确需要在AB和CD上分别确定一个点作为转折点。
2.若已知AB,CD上的定点P1,P2,那么Time = AP1/P + P1P2/R + P2D/Q;
3.若我们能够先知道点P1(x1,y1),那么可以根据P2(x2,y2)求出最快的时间Time。
Time = AP1/P + sqrt((x1-x2)^2 + (y1-y2)^2)/R + sqrt((x2-D.x) + (y2-D.y))/Q;
/************************************************************************* > File Name: hdu3400.cpp > Author: BSlin > Mail: > Created Time: 2013年09月29日 星期日 22时07分59秒 ************************************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <algorithm> #include <iterator> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #define MP make_pair #define INF (1<<30) #define PI acos(-1.0) #define esp 1e-5 const int dx[4]={0,0,0,0}; using namespace std; #define read freopen("in.txt","r",stdin) #define write freopen("out.txt","w",stdout) #if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__) #define LL __int64 #define LLS "%" "I" "6" "4" "d" #else #define LL long long #define LLS "%" "l" "l" "d" #endif struct Point { double x,y; }A,B,C,D; int P,Q,R; Point Get_Point (Point A, Point B) { Point Mid; Mid.x = (A.x + B.x) / 2.0; Mid.y = (A.y + B.y) / 2.0; return Mid; } double Get_Len (Point A, Point B) { return sqrt((A.x -B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)); } double Get_Time (Point p) { Point lift = C,right = D,mid,mmid; double mid_time = 0,mmid_time = 1; while(fabs(mid_time - mmid_time) > esp) { mid = Get_Point(lift,right); mmid = Get_Point(mid,right); mid_time = Get_Len(p,mid) / R + Get_Len(mid,D) / Q; mmid_time = Get_Len(p,mmid) / R + Get_Len(mmid,D) / Q; if(mid_time - mmid_time >= esp) lift = mid; else right = mmid; } return mid_time + Get_Len(A,p) / P; } int main(int argc, char** argv) { //read; int t; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf%d%d%d",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y,&P,&Q,&R); Point lift = A,right = B,mid,mmid; double mid_time = 0,mmid_time = 1; while(fabs(mid_time - mmid_time) > esp) { mid = Get_Point(lift,right); mmid = Get_Point(mid,right); mid_time = Get_Time(mid); mmid_time = Get_Time(mmid); if(mid_time - mmid_time >= esp) lift = mid; else right = mmid; } printf("%.2f\n", mid_time); } return 0; }
相关文章推荐
- HDU 3400 Line belt 嵌套三分搜索
- Line belt HDU - 3400 三分
- Line belt+hdu+三分搜索
- 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 3400 Line belt (三分套三分)
- HDU 3400 Line belt 三分
- hdu 3400 Line belt (三分套三分)
- hdu 3400 Line belt(多重三分)
- HDU 3400 Line belt(嵌套三分)
- HDU 3400 Line belt (三分嵌套)