Code Forces 590 B. Chip 'n Dale Rescue Rangers(二分)
来源:互联网 发布:淘宝新店推广 编辑:程序博客网 时间:2024/04/30 16:53
Description
一架飞机需要从(x1,y1)飞到(x2,y2),飞机相对于风的最大飞行速度是v,风速在前ts为(vx,vy),之后变为(wx,wy),问飞机飞到目的地所花费的最少时间是多少(忽略飞机的变速时间)
Input
第一行为四个浮点数x1,y1,x2,y2分别表示起点和终点坐标,第二行两个整数v和t分别表示飞机相对于风的最大飞行速度以及风速(vx,vy)的持续时间,之后为四个浮点数vx,vy,wx,wy分别表示两个风速,保证vx^2+vy^2< v^2且wx^2+wy^2< v^2)
(|x1|, |y1|, |x2|, |y2| ≤ 10 000,0 < v, t ≤ 1000)
Output
输出飞机到达目的地所花费的最少时间,结果需保证与正确答案的相对及绝对误差均不超过1e-6
Sample Input
0 0 5 5
3 2
-1 -1
-1 0
Sample Output
3.729935587093555327
Solution
二分最短时间x,换参考系为风,先算出飞机静止时相对于风运动xs后的位置(x3,y3),再通过判断(x2,y2)和(x3,y3)的距离d与v*x的关系来判断飞机是否可达即可
Code
#include<stdio.h>#include<math.h>double X1,Y1,X2,Y2,v,t,vx,vy,wx,wy;double dis(double x1,double y1,double x2,double y2){ return (double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}int check(double x){ double x3,y3; if(x>t) { x3=X1+t*vx+(x-t)*wx; y3=Y1+t*vy+(x-t)*wy; } else { x3=X1+x*vx; y3=Y1+x*vy; } double d=dis(X2,Y2,x3,y3); if(d<v*v*x*x) return true; return false;}int main(){ while(~scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2)) { scanf("%lf%lf%lf%lf%lf%lf",&v,&t,&vx,&vy,&wx,&wy); double l=0,r=1e10; int res=1e6; while(res--) { double mid=(l+r)/2; if(check(mid)) r=mid; else l=mid; } printf("%.18lf\n",l); } return 0;}
0 0
- Code Forces 590 B. Chip 'n Dale Rescue Rangers(二分)
- Codeforces 590B Chip 'n Dale Rescue Rangers(二分)
- CF 590B Chip 'n Dale Rescue Rangers(二分)
- Codeforces 590B Chip 'n Dale Rescue Rangers(二分)
- 二分 Codeforces591D Chip 'n Dale Rescue Rangers
- Codeforces 590B Chip 'n Dale Rescue Rangers
- Codeforces 590B Chip 'n Dale Rescue Rangers
- CodeForces 590B Chip 'n Dale Rescue Rangers 题解
- Codeforces 591D Chip 'n Dale Rescue Rangers【思维+二分】
- Codeforces #591 D Chip 'n Dale Rescue Rangers(二分查找/转换参考系)
- Codeforces Round #327 (Div. 1) B. Chip 'n Dale Rescue Rangers
- Codeforces Round #327 (Div. 1) B题: Chip 'n Dale Rescue Rangers [数学题]
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- Codeforces 591D Chip 'n Dale Rescue Rangers
- 【Codeforces Round #327 (Div. 2) D】【贪心+二分】 Chip 'n Dale Rescue Rangers 救援任务 变风向
- Codeforces Round #327 (Div. 2)D. Chip 'n Dale Rescue Rangers
- Codeforces Round #327 (Div. 2)D. Chip 'n Dale Rescue Rangers
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers
- LibGDX_4.2: 演员(Actor)
- UI基础-图片异步下载、KVO
- jQuery之dom操作(遍历节点)
- Life Forms 后缀数组 不小于k个字符串中的最长子串
- 指针类型学习总结-- this指针
- Code Forces 590 B. Chip 'n Dale Rescue Rangers(二分)
- Boyer-Moore算法--C语言实现(简单易懂)
- STL学习小结3
- C++ pair(对组)用法
- java BigDecimal介绍
- hello world
- C/C++ 中头文件相互包含引发的问题
- 璞玉有瑕,贵在琢磨
- android(25)(android下实现多线程断点下载)