Codeforces Round #327 (Div. 1) B题: Chip 'n Dale Rescue Rangers [数学题]
来源:互联网 发布:域名被墙 301跳转 编辑:程序博客网 时间:2024/04/30 10:20
题意:一艘飞船最大驾驶速度为Vmax,现在点X1,Y1,想要飞到点X2,Y2,前T秒的有风速为VX,VY,T秒后的风速为WX,WY,问最短达到时间。(保证风速小于Vmax)
解法:一开始三分套二分,神奇的过了初测,但最后果然还是WA了(应该是我选取的角度有问题吧……),后来推了推公式就A了。只要将三段位移分开来考虑,最后行驶速度必然是Vmax才能最短时间到达,列个勾股定理的公式推导一下即可。
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<iostream>#include<stdlib.h>#include<set>#include<map>#include<queue>#include<vector>#include<bitset>#pragma comment(linker, "/STACK:1024000000,1024000000")template <class T>bool scanff(T &ret){ //Faster Input char c; int sgn; T bit=0.1; if(c=getchar(),c==EOF) return 0; while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); if(c==' '||c=='\n'){ ret*=sgn; return 1; } while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10; ret*=sgn; return 1;}#define inf 1073741823#define llinf 4611686018427387903LL#define PI acos(-1.0)#define lth (th<<1)#define rth (th<<1|1)#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)#define mem(x,val) memset(x,val,sizeof(x))#define mkp(a,b) make_pair(a,b)#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define pb(x) push_back(x)using namespace std;typedef long long ll;typedef pair<int,int> pii;double ox1,oy1,ox2,oy2;double vx1,vy1,vx2,vy2;double vmax,t;double dx,dy;double eps=1e-9;double gettime1(double vx,double vy,double ox,double oy){ double lenx=ox2-ox; double leny=oy2-oy; double a=vx*vx+vy*vy-vmax*vmax; double b=-2.0*(vx*lenx+vy*leny); double c=(lenx*lenx+leny*leny); double x1= (-b-sqrt(b*b-4.0*a*c))/a/2.0; double x2= (-b+sqrt(b*b-4.0*a*c))/a/2.0; if(x1>-eps)return x1; return x2;}double gettime2(double vx,double vy,double ox,double oy){ double lenx=ox2-ox; double leny=oy2-oy; double a=vx*vx+vy*vy-vmax*vmax; double b=-2.0*(vx*(lenx+t*vx)+vy*(leny+t*vy)); double c=(lenx+t*vx)*(lenx+t*vx)+(leny+t*vy)*(leny+t*vy); double x1= (-b-sqrt(b*b-4.0*a*c))/a/2.0; double x2= (-b+sqrt(b*b-4.0*a*c))/a/2.0; if(x1>-eps)return x1; return x2;}int main(){ scanff(ox1);scanff(oy1); scanff(ox2);scanff(oy2); scanff(vmax);scanff(t); scanff(vx1);scanff(vy1); scanff(vx2);scanff(vy2); double t1=gettime1(vx1,vy1,ox1,oy1); double t2=gettime2(vx2,vy2,ox1+vx1*t,oy1+vy1*t); if(t1<t)printf("%.15f\n",t1); else printf("%.15f\n",t2); return 0;}
0 0
- Codeforces Round #327 (Div. 1) B题: Chip 'n Dale Rescue Rangers [数学题]
- Codeforces Round #327 (Div. 1) B. 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 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 题解
- Codeforces 590B Chip 'n Dale Rescue Rangers(二分)
- 【Codeforces Round #327 (Div. 2) D】【贪心+二分】 Chip 'n Dale Rescue Rangers 救援任务 变风向
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- Codeforces 591D Chip 'n Dale Rescue Rangers
- Codeforces 591D Chip 'n Dale Rescue Rangers【思维+二分】
- CF 590B Chip 'n Dale Rescue Rangers(二分)
- 二分 Codeforces591D Chip 'n Dale Rescue Rangers
- Codeforces #591 D Chip 'n Dale Rescue Rangers(二分查找/转换参考系)
- Code Forces 590 B. Chip 'n Dale Rescue Rangers(二分)
- iOS 百度地图反编码地理位置信息
- SQLServer 里面的 DDL,DML,DCL,TCL
- freemarker循环遍历Map
- 汕头正宗的牛肉丸多少钱一斤的
- LeetCode---Spiral Matrix II
- Codeforces Round #327 (Div. 1) B题: Chip 'n Dale Rescue Rangers [数学题]
- 库函数strcpy/strlen的工作方式
- 几道笔试题
- android中的常用线程池区别--转载
- 通过弹出层实现新建功能 ruby on rails
- Android基础之图片的压缩算法
- Eclipse 安装 EasyShell 插件(打开项目所在本地磁盘位置)
- 016.Assign Operator 赋值运算
- MFC对话框——访问Edit对话框