题解:P7069 [NWRRC 2014] Joy of Flight
Union_Find · · 题解
注意到,这道题比较简单,但是我调了10 min。
题目是要让我们在每一秒内移动,使得飞机最终可以到达。
一开始我想的是贪心,在每次操作的时候选择超目标方向移动最远距离。但是很快就想到 hack 了。因为我们有可能你往上走了之后,有一阵风使得你向上走了很远,使得你更远了。所以正解应该是要整体考虑。
注意到,向量的加法具有结合律和交换律。所以我们可以先让飞机走完所有的风,然后再考虑自己飞。假设所有风吹完之后位置是
那如何输出方案呢?很简单,我们可以直接每次自己飞的向量设为
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define N 1000005
#define f(x) ((x) * (x))
il ll rd(){
ll s = 0, w = 1;
char ch = getchar();
for (;ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;
for (;ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 1) + (s << 3) + ch - '0');
return s * w;
}const long double eps = 1e-12;
ll sx, sy, tx, ty, n, k, v, t[N], wx[N], wy[N], x, y;
int main(){
sx = rd(), sy = rd(), tx = rd(), ty = rd(), n = rd(), k = rd(), v = rd();
for (int i = 1; i <= n; i++) t[i] = rd(), wx[i] = rd(), wy[i] = rd();
t[n + 1] = k;
x = sx, y = sy;
for (int i = 0, j = 1; i < k; i++){
if (t[j + 1] == i) j++;
x += wx[j], y += wy[j];
}
long double dis = sqrt(f(tx - x) + f(ty - y));
long double ux = sx, uy = sy, px = 1.0 * (tx - x) / k, py = 1.0 * (ty - y) / k;
if (dis > v * k) return 0 & puts("No");
else puts("Yes");
for (int i = 0, j = 1; i < k; i++){
if (t[j + 1] == i) j++;
ux += px + wx[j], uy += py + wy[j], printf ("%.50Lf %.50Lf\n", ux, uy);
}
return 0;
}