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

题意:一艘飞船最大驾驶速度为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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值