Codeforces Gym 100531J Joy of Flight 变换坐标系

时间:2023-03-08 16:45:45

Joy of Flight

题目连接:

http://codeforces.com/gym/100531/attachments

Description

Jacob likes to play with his radio-controlled aircraft. The weather today is pretty windy and Jacob has

to plan flight carefully. He has a weather forecast — the speed and direction of the wind for every second

of the planned flight.

The plane may have airspeed up to vmax units per second in any direction. The wind blows away plane

in the following way: if airspeed speed of the plane is (vx, vy) and the wind speed is (wx, wy), the plane

moves by (vx + wx, vw + wy) each second.

Jacob has a fuel for exactly k seconds, and he wants to learn, whether the plane is able to fly from start

to finish in this time. If it is possible he needs to know the flight plan: the position of the plane after

every second of flight.

Input

The first line of the input file contains four integers Sx, Sy, Fx, Fy — coordinates of start and finish

(−10 000 ≤ Sx, Sy, Fx, Fy ≤ 10 000).

The second line contains three integers n, k and vmax — the number of wind condition changes, duration

of Jacob’s flight in seconds and maximum aircraft speed (1 ≤ n, k, vmax ≤ 10 000).

The following n lines contain the wind conditions description. The i-th of these lines contains integers

ti

Output

The first line must contain “Yes” if Jacob’s plane is able to fly from start to finish in k seconds, and “No”

otherwise.

If it can to do that, the following k lines must contain the flight plan. The i-th of these lines must contain

two floating point numbers x and y — the coordinates of the position (Pi) of the plane after i-th second

of the flight.

The plan is correct if for every 1 ≤ i ≤ k it is possible to fly in one second from Pi−1 to some point

Qi

, such that distance between Qi and Pi doesn’t exceed 10−5

, where P0 = S. Moreover the distance

between Pk and F should not exceed 10−5 as well.

Sample Input

1 1 7 4

2 3 10

0 1 2

2 2 0

Sample Output

Yes

3 2.5

5 2.5

7 4

Hint

题意

给你一个起点和终点,然后会有风,问你能否在k秒内到达终点

如果可以的话,就输出每一秒之后,你在哪儿

题解:

和CF的某道题一样的,把坐标系变换一下,把风直接的按在终点倒着跑

然后直接看一下时间是否小于等于k就好了

如果小于的话,就直接跑平均速度就好了

代码

#include<bits/stdc++.h>
using namespace std; double sx,sy,fx,fy;
int n,k,t[20005];
double v,wx[20005],wy[20005];
double vx,vy;
int tot = 0;
double winx=0,winy=0;
int check(int mid)
{
tot = 0,winx = winy = 0;
double ex = fx,ey = fy;
for(int i=0;i<mid;i++)
{
if(tot<n&&t[tot]==i)
winx=wx[tot],winy=wy[tot],tot++;
ex-=winx,ey-=winy;
}
double dis = sqrt((ex-sx)*(ex-sx)+(ey-sy)*(ey-sy));
if(dis/v>mid)return 0;
return 1;
}
int main()
{
freopen("joy.in","r",stdin);
freopen("joy.out","w",stdout);
cin>>sx>>sy>>fx>>fy;
cin>>n>>k>>v;
for(int i=0;i<n;i++)
cin>>t[i]>>wx[i]>>wy[i];
int L = 0;
for(;L<=k+5;L++)
if(check(L))
break;
if(L>k)return puts("No");
double ex = fx,ey = fy;
tot = winx = winy = 0;
for(int i=0;i<L;i++)
{
if(tot<n&&t[tot]==i)
winx=wx[tot],winy=wy[tot],tot++;
fx-=winx,fy-=winy;
}
double l = fx - sx;
double h = fy - sy;
double dis = sqrt(l*l+h*h);
double vx = v * l / dis;
double vy = v * h / dis;
tot = winx = winy = 0;
puts("Yes");
if(L==0)L++;
for(int i=0;i<L-1;i++)
{
if(tot<n&&t[tot]==i)
winx=wx[tot],winy=wy[tot],tot++;
sx += vx + winx;
sy += vy + winy;
printf("%.6f %.6f\n",sx,sy);
}
for(int i=L;i<=k;i++)
printf("%.6f %.6f\n",ex,ey);
}