Line belt
来源:互联网 发布:唐代男子服饰知乎 编辑:程序博客网 时间:2024/05/16 23:33
Line belt
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 9 Accepted Submission(s) : 5
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,从A到D,如果在直线AB上行驶有速度P,在直线CD上行驶有速度Q,其它地方有速度R,求A到D的最短花费时间。
解题思路:
首先固定AB上一点,第一次我们设把这点设为mid1=B,然后三分去CD上找一点mid2,使A到D花的时间最少。然后固定CD上的mid2,用三分法去AB上找一点mid1,使A->mid1->mid2->D,花费时间最少,重复上述过程。
不知道错哪了...
#include<cstdio>#include<cmath>#define min(a,b) (a>b?b:a)#define esp 1e-8double p,q,r;struct point{ double x,y;}A,B,C,D;double get_dis(point M,point N){ return sqrt((N.x-M.x)*(N.x-M.x)+(N.y-M.y)*(N.y-M.y));}point get_mid(point M,point N){ point mid; mid.x=(N.x+M.x)/2.0; mid.y=(N.y+M.y)/2.0; return mid;}double get_time(point M,point N){ return get_dis(A,M)/p+get_dis(M,N)/r+get_dis(N,D)/q;}double three2(point N){ point min=D,max=C,M2,M3;//二分点,三分点 double time2,time3; while(get_dis(min,max)>esp) { M2=get_mid(min,max);time2=get_time(N,M2); M3=get_mid(M2,max);time3=get_time(N,M3); if(time2<time3) max=M3; else min=M2; } return min(time2,time3);}using namespace std;int main(){ int cases; scanf("%d",&cases); while(cases--) { 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); point min=A,max=B,M2,M3; double time2,time3; while(get_dis(min,max)>esp) { M2=get_mid(min,max); M3=get_mid(M2,max); time2=three2(M2); time3=three2(M3); if(time2>time3) min=M2; else max=M3; } printf("%.2lf\n",min(time2,time3)); } return 0;}
- Line belt
- Line belt
- HDU 3400 Line belt
- HDU Line belt
- hdu3400 Line belt 三分法
- hdu3400 Line belt
- hdu3400 Line belt
- HDU 3400 Line belt
- POJ 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
- 6Line belt
- 1006 Line belt
- 1006 Line belt
- hello world
- new、operator new和placement new
- 读《培训师》摘录笔记(二)
- zoj 2834 蛮有意思的树形DP
- 如何调试makefile
- Line belt
- Android动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整
- Lisp 匿名递归函数 v2:在 Common Lisp 中实现 Clojure 的 fn
- 深入理解javascript系列(1):高质量JavaScript代码书写基本要点
- poj 1850 code(杨辉三角+组合数)
- extjs4.0——window
- JAVA 一个月多少天
- [java]正则表达式
- C++编译、链接过程