【Codeforces Round #327 (Div. 2) D】【贪心+二分】 Chip 'n Dale Rescue Rangers 救援任务 变风向
来源:互联网 发布:天龙八部神鼎数据 编辑:程序博客网 时间:2024/04/28 14:29
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;double K(double x){return x*x;}int main(){int x1,y1,x2,y2;int V,T;int Vx,Vy,Wx,Wy;while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){scanf("%d%d",&V,&T);scanf("%d%d",&Vx,&Vy);scanf("%d%d",&Wx,&Wy);double X=x2-x1;double Y=y2-y1;double x=X-T*Vx;double y=Y-T*Vy;double dis=sqrt(K(x)+K(y));double t=dis/V;if(t<=T){double l=0;double r=T;for(int tim=1;tim<=200;tim++){double m=(l+r)/2;x=X-m*Vx;y=Y-m*Vy;dis=sqrt(K(x)+K(y));t=dis/V;t<=m?r=m:l=m;}printf("%.10f\n",l);}else{X-=T*Vx;Y-=T*Vy;double l=0;double r=1e16;for(int tim=1;tim<=200;tim++){double m=(l+r)/2;x=X-(m-T)*Wx;y=Y-(m-T)*Wy;dis=sqrt(K(x)+K(y));t=dis/V;t<=m?r=m:l=m;}printf("%.10f\n",l);}}return 0;}/*【trick&&吐槽】能以规律总结方式做的题,不要同分类讨论和模拟做。很容易把问题繁琐化,造成AC压力。【题意】我们在(x1,y1),要前往(x2,y2)。我们的速度最大为V。前在T秒的时间里,我们会被强制加上一个(vx,vy)的速度,在T秒之后的时间里,我们会被加上(wx,wy)的速度,我们可以任意改变速度的大小和方向,只是不能超过V。现在问你,最早到达(x2,y2)的时间是什么。【类型】讨论+模拟?不!贪心+二分。【分析】对于我这种渣渣,凡是涉及到解方程的,我都最好还是用二分、三分暴力出解吧。解方程对于我太容易爆炸了QwQ。这里有个时间分界点T,也是我们讨论的着手点。我们首先肯定要判断自己能否在时间T之前到达(x2,y2)。如何判定呢?首先要有一个速度可以叠加的思想。临界点是T。如果恰好是在时刻T到达。那么我们的位移其实可以说是V速度之外的位移量,具体上是——(x2-x1+vy*T,y2-y1+vx*T)只要在T时刻内可以达成这个位移量,那么就可以在T之前到达。至于具体时间?二分吧。然后如果无法在T之前到达,那么我们的位移量就变成了——(x2-x1+vy*T+wy*(t-T),y2-y1+vx*T+wx*(t-T))至于具体时间?二分吧。这样就可以以极小的思维复杂度与变成复杂度AC这道题。【时间复杂度&&优化】O(二分)【数据】Input0 0 5 53 2-1 -1-1 0Output3.729935587093555327Input0 0 0 1000100 1000-50 050 0Output11.547005383792516398*/
1 0
- 【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
- Codeforces 591D 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 590B Chip 'n Dale Rescue Rangers(二分)
- Codeforces 590B Chip 'n Dale Rescue Rangers(二分)
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- Codeforces 591D Chip 'n Dale Rescue Rangers
- Codeforces #591 D Chip 'n Dale Rescue Rangers(二分查找/转换参考系)
- 二分 Codeforces591D Chip 'n Dale Rescue Rangers
- CF 590B 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 题解
- Code Forces 590 B. Chip 'n Dale Rescue Rangers(二分)
- 进程间通信简介(六)——信号量
- Spring从2.5.6至3.1.2过程详解
- 仿知乎程序(二)fragment的切换以及toolbar在不同页面下显示的menu不同
- C# 下载文件名重命名的问题
- 网站开发进阶(七)**网站访问综合问题分析
- 【Codeforces Round #327 (Div. 2) D】【贪心+二分】 Chip 'n Dale Rescue Rangers 救援任务 变风向
- Android 5.0源码分析---ContentProvider中的ContentObserver研究
- iOS9 HTTPS
- 修改awr报告的保留时间
- 尝试建个人博客
- 数据库的读写分离
- APP发布测试流程
- 请求转发与重定向的区别
- Js中关于数组常用函数的介绍