hdoj3400Line belt【三分法】
2015-09-24 07:09
302 查看
Line beltTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3324 Accepted Submission(s): 1296 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 |
解题:思路在AB上三分确定转向CD的位置在CD上三分确定从AB来的进入道路哪一点算出最小时间即可
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #define eps 1e-8 using namespace std; int sgn(double n){ if(fabs(n)<eps)return 0; else if(n<0)return -1; return 1; } struct point{ double x,y; }A,B,C,D; double p,q,r; double dist(point p1,point p2){ return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); } double Three2(point a){ point left=C,right=D; point mid,mmid; double t1,t2; int size=100; while(size--){ mid.x=(left.x+right.x)/2.0; mid.y=(left.y+right.y)/2.0; mmid.x=(mid.x+right.x)/2.0; mmid.y=(mid.y+right.y)/2.0; t1=dist(a,mid)/r+dist(mid,D)/q; t2=dist(a,mmid)/r+dist(mmid,D)/q; if(t1>t2) left=mid; else right=mmid; } return t1; } double Three1(){ point left=A,right=B; point mid,mmid; double t1,t2; int size=100; while(size--){ mid.x=(left.x+right.x)/2.0; mid.y=(left.y+right.y)/2.0; mmid.x=(mid.x+right.x)/2.0; mmid.y=(mid.y+right.y)/2.0; t1=dist(A,mid)/p+Three2(mid); t2=dist(A,mmid)/p+Three2(mmid); if(t1>t2) left=mid; else right=mmid; } return t1; } int main() { int t,i,j,k; 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); printf("%.2lf\n",Three1()); } return 0; }
相关文章推荐
- HDU 5451
- Binary Tree Zigzag Level Order Traversal 解答
- 雅虎-雷鳥-海猴
- ant使用手册
- 2015年秋季阅读计划
- COGS 2027 RQNOJ 72 拔河比赛 背包
- USB数据传输形象讲解
- 各类知识点文章收集
- hdoj 2647 Reward 【逆向拓扑排序 队列】
- 提问:恢复Mysql的备份文件失败
- 提问:由于类没有找到,工作失败
- "如何将本地开发的系统迁移到云端,数据存储问题
- "如何将本地开发的系统迁移到云端,数据存储问题
- "如何将本地开发的系统迁移到云端,数据存储问题
- Moving Zeros
- "如何将本地开发的系统迁移到云端,数据存储问题
- H-Index I, II
- "分享:围观龙虎斗:谷歌GCE
- 简洁的for(3)的define
- 云计算学习