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

CodeForces 590B Chip 'n Dale Rescue Rangers 题解

2016-01-21 17:15 387 查看
【题目大意】:
某救援队打算从(x1,y1)到目的地(x2,y2),已知在[0,t]时间内风的向量表示为(Vx,Vy),t时间以后的风的向量表示为(Wx,Wy),且救援队的静风速度最大为Vmax。救援队在途中可任意更改前进方向和速度,求救援队到达目的地的最短时间。(保证风速向量的模小于Vmax)。(原题及样例见下)
Chip 'n Dale Rescue Rangers

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road.

We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1),
and the distress signal came from the point (x2, y2).

Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed 

 meters
per second.

Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will
be defined by the vector (vx, vy) for
the nearest t seconds, and then will change to (wx, wy).
These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y),
while its own velocity relative to the air is equal to zero and the wind (ux, uy) is
blowing, then after 

 seconds
the new position of the dirigible will be 

.

Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose
the face in front of Gadget. Dale has asked you to find the right answer.

It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air.

Input

The first line of the input contains four integers x1, y1, x2, y2 (|x1|,  |y1|,  |x2|,  |y2| ≤ 10 000) —
the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively.

The second line contains two integers 

 and t (0 < v, t ≤ 1000),
which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively.

Next follow one per line two pairs of integer (vx, vy) and (wx, wy),
describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed
that 

 and 

.

Output

Print a single real value — the minimum time the rescuers need to get to point (x2, y2).
You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b.
The checker program will consider your answer correct, if 

.

Sample test(s)

input
0 0 5 5
3 2
-1 -1
-1 0


output
3.729935587093555327


input
0 0 0 1000
100 1000
-50 0
50 0


output
11.547005383792516398


【分析】:
由于要求最小时间,且满足二分答案所需性质(存在不满足和满足要求的唯一分界点,且单调),因而我们可以先二分答案举出一个时间,然后判断这个时间time是否合法(能否到达目的地)。
接下来的问题就是如何判断了。我们可以把问题拆成两个方面(拆成两个分运动):先处理风的分运动(即救援队不动,由风吹time时间,到达坐标(x,y)),然后处理救援队的分运动(让救援队从(x,y)运动到目的地,看所需时间是否小于等于time,若是则合法)。这样,问题就解决了。
【代码】:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int x1_1,y1_1,x2_1,y2_1,vmax,t,vx,vy,wx,wy;
double ans;
double distsqr(double x1_1,double y1_1,double x2_1,double y2_1)
{
return (x1_1-x2_1)*(x1_1-x2_1)+(y1_1-y2_1)*(y1_1-y2_1);
}
bool check(double Time)
{
double laterx,latery;
if(Time-t*1.0>=1e-7)
{
laterx=x1_1*1.0+vx*t*1.0+wx*1.0*(Time-1.0*t);
latery=y1_1*1.0+vy*t*1.0+wy*1.0*(Time-1.0*t);
}
else
{
laterx=x1_1*1.0+vx*1.0*Time;
latery=y1_1*1.0+vy*1.0*Time;
}
if(distsqr(laterx,latery,x2_1*1.0,y2_1*1.0)<(vmax*1.0*Time)*(vmax*1.0*Time))
return true;
else  return false;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
scanf("%d%d%d%d%d%d",&x1_1,&y1_1,&x2_1,&y2_1,&vmax,&t);
scanf("%d%d",&vx,&vy);
scanf("%d%d",&wx,&wy);
double left=0.0,right=100000000.0;
while(fabs(right-left)>1e-7)
{
double middle=(left+right)/2.0;
if(check(middle))
{
right=middle;
ans=middle;
}
else  left=middle;
}
printf("%.18lf\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: