官方题解:「QFOI R3」航线交汇
本题解是「QFOI R3」航线交汇的官方题解。
如果 No 即可。以下只考虑
当且仅当 Always。
如果 No。
否则,起飞时一架飞机在另一架飞机前面,降落时到了后面,那么途中一定存在一个时刻使得它们在同一个位置。不妨设所有飞机在时刻
解得:
输出
时间复杂度
//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x, y, z) for(int x = (y); x <= (z); ++x)
#define per(x, y, z) for(int x = (y); x >= (z); --x)
#define endl '\n'
using namespace std;
typedef long long ll;
int n, d, s0, t0, h0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(12);
cin >> n >> d;
cin >> s0 >> t0 >> h0;
while(n--) {
int s, t, h;
cin >> s >> t >> h;
if(abs(h0 - h) > d) cout << "No" << endl;
else if(s0 == s && t0 == t) cout << "Always" << endl;
else if(s0 < s && t0 < t || s0 > s && t0 > t) cout << "No" << endl;
else {
double x = 1.0 * (s - s0) / (t0 - s0 + s - t);
cout << s0 + x * (t0 - s0) << endl;
}
}
return 0;
}