您的位置:首页 > 产品设计 > UI/UE

Codeforces Round #327 (Div. 1) B题: Chip 'n Dale Rescue Rangers [数学题]

2015-10-27 17:07 375 查看
题意:一艘飞船最大驾驶速度为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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: