题解:P14914 「QFOI R3」航线交汇
CJY_Holmes · · 题解
思路
定义小 R 坐的飞机起点为
- 小 R 的飞机位置:
s_0+p(t_0-s_0) 。 - 第
i 个飞机的位置:s_i+p(t_i-s_i) 。
则有方程:
先求得
Code
#include<bits/stdc++.h>
using namespace std;
int n,d,s0,t0,h0;
int main(){
cin>>n>>d>>s0>>t0>>h0;
while(n--){
int s,t,h;cin>>s>>t>>h;
if(abs(h0-h)>d){cout<<"No\n";continue;}//检查高度差
int v=(t-s)-(t0-s0);//计算分母
if(!v){//排除分母为 $0$
if(s==s0) cout<<"Always\n";//速度相同
else cout<<"No\n";
}else{
long double p=(s0-s)*1.0/v;//计算相遇时间比例 p
if(p>=0&&p<=1){//检查 p 是否在 [0,1] 范围内
long double pos=s0+p*(t0-s0);//计算位置
printf("%.12Lf\n",pos);
}else cout<<"No\n";
}
}
}