Codeforces 591D Chip 'n Dale Rescue Rangers【思维+二分】
2017-10-23 18:16
525 查看
D. 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
![](http://codeforces.com/predownloaded/31/c9/31c9ad44d9dbd5cc9f10037cfe74239a617f8181.png)
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
![](http://codeforces.com/predownloaded/3a/3c/3a3c8e72a1901b550520a6a5a7d522c7d3e2edd5.png)
seconds
the new position of the dirigible will be
![](http://codeforces.com/predownloaded/16/68/1668c29c905aff373d3ab7a12a6d980670795f70.png)
.
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
![](http://codeforces.com/predownloaded/31/c9/31c9ad44d9dbd5cc9f10037cfe74239a617f8181.png)
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
![](http://codeforces.com/predownloaded/4d/d4/4dd4ef915fc59a772178587cb2858c4cdeac6d59.png)
and
![](http://codeforces.com/predownloaded/1b/a6/1ba6e4d20c2788df1f2385459224b5d848c214ca.png)
.
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
![](http://codeforces.com/predownloaded/c6/2e/c62ea64d4651240724c5ac4779b671c741edec24.png)
.
Examples
input
output
input
output
题目大意:
我们要从点(x1,y1)到达点(x2,y2),我们飞机的最大速度是v,现在已知t秒前的风速向量是(vx,vy),t妙后的风速向量是(wx,wy);问我们需要航行多长时间到达目的地。
思路:
①首先我们能够确定,如果时间t能够到达目的地的话,那么t+1时刻也能够到达目的地。所以我们二分一个时间,来check一下即可。
②对于当前枚举的时间mid,我们计算mid时间内,从起点被风所影响能够到达的点(posx,posy),然后计算(posx,posy)和终点的距离,如果我们有:v*mid>=dist,那么对应时间mid内一定能够到达终点,同时减少R,继续二分即可。
过程维护一下。
Ac代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x1,y1,x2,y2,v,t,vx,vy,wx,wy;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&v,&t,&vx,&vy,&wx,&wy))
{
double ans=0;
double l=0;
double r=1e9;
for(int i=0;i<120;i++)
{
double mid=(l+r)/2;
double posx=x1+min(t,mid)*vx+max(mid-t,0.0)*wx;
double posy=y1+min(t,mid)*vy+max(mid-t,0.0)*wy;
double dist=sqrt((posx-x2)*(posx-x2)+(posy-y2)*(posy-y2));
if(v*mid>=dist)r=mid,ans=mid;
else l=mid;
}
printf("%.12lf\n",ans);
}
}
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
![](http://codeforces.com/predownloaded/31/c9/31c9ad44d9dbd5cc9f10037cfe74239a617f8181.png)
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
![](http://codeforces.com/predownloaded/3a/3c/3a3c8e72a1901b550520a6a5a7d522c7d3e2edd5.png)
seconds
the new position of the dirigible will be
![](http://codeforces.com/predownloaded/16/68/1668c29c905aff373d3ab7a12a6d980670795f70.png)
.
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
![](http://codeforces.com/predownloaded/31/c9/31c9ad44d9dbd5cc9f10037cfe74239a617f8181.png)
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
![](http://codeforces.com/predownloaded/4d/d4/4dd4ef915fc59a772178587cb2858c4cdeac6d59.png)
and
![](http://codeforces.com/predownloaded/1b/a6/1ba6e4d20c2788df1f2385459224b5d848c214ca.png)
.
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
![](http://codeforces.com/predownloaded/c6/2e/c62ea64d4651240724c5ac4779b671c741edec24.png)
.
Examples
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
题目大意:
我们要从点(x1,y1)到达点(x2,y2),我们飞机的最大速度是v,现在已知t秒前的风速向量是(vx,vy),t妙后的风速向量是(wx,wy);问我们需要航行多长时间到达目的地。
思路:
①首先我们能够确定,如果时间t能够到达目的地的话,那么t+1时刻也能够到达目的地。所以我们二分一个时间,来check一下即可。
②对于当前枚举的时间mid,我们计算mid时间内,从起点被风所影响能够到达的点(posx,posy),然后计算(posx,posy)和终点的距离,如果我们有:v*mid>=dist,那么对应时间mid内一定能够到达终点,同时减少R,继续二分即可。
过程维护一下。
Ac代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x1,y1,x2,y2,v,t,vx,vy,wx,wy;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&v,&t,&vx,&vy,&wx,&wy))
{
double ans=0;
double l=0;
double r=1e9;
for(int i=0;i<120;i++)
{
double mid=(l+r)/2;
double posx=x1+min(t,mid)*vx+max(mid-t,0.0)*wx;
double posy=y1+min(t,mid)*vy+max(mid-t,0.0)*wy;
double dist=sqrt((posx-x2)*(posx-x2)+(posy-y2)*(posy-y2));
if(v*mid>=dist)r=mid,ans=mid;
else l=mid;
}
printf("%.12lf\n",ans);
}
}
相关文章推荐
- Codeforces 807E Prairie Partition 贪心思维+二分
- Codeforces 672D Robin Hood 二分判定+思维
- Codeforces 807C Success Rate【二分+数学思维】
- codeForces 535C.Tavas and Karafs(二分+思维)
- Codeforces 359D Pair of Numbers【思维+二分+区间Gcd+区间最小值RMQ】
- codeforces-729【思维】【二分】
- Codeforces 365C 思维或二分
- Codeforces 817C Really Big Numbers【思维+二分】
- Codeforces 622C Not Equal on a Segment【思维预处理+二分】
- codeforces 672D D. Robin Hood (二分+思维)
- codeForces 672D.Robin Hood(思维+二分)
- Codeforces 782B The Meeting Place Cannot Be Changed【二分+思维】
- Codeforces 864D D. Make a Permutation!【思维+线段树+二分+这是一个煞笔做法】
- Codeforces 702C Cellular Network【二分+思维】CF的题好多二分啊~
- codeforces 485D. Maximum Value(二分+思维)
- CodeForces 672D Robin Hood(二分 + 思维)
- codeforces 895B XK Segments 思维 二分
- Codeforces 675C Money Transfers 【思维】 + 675D Tree Construction 【二分】
- CodeForces 672D (思维+二分)
- Codeforces 689C Mike and Chocolate Thieves【二分+思维】