我们发现,当 为 和 的中点时, 一定是最优距离。
证明
若 不为 和 的中点,则距离两个点个点的距离分别为 和 ,取 一定是不如去中点优的。
所以我们可以写出代码:
#include<bits/stdc++.h>
#define int __int128
using namespace std;
int C,l,v,t;
inline int read(){
int f=0;char ch=getchar();
while(ch<48||ch>57)ch=getchar();
while(ch>47&&ch<58)f=(f<<3)+(f<<1)+(ch^48),ch=getchar();
return f;
}
void print(int a){
if(a>9)print(a/10);
putchar(a%10+'0');
}
signed main(){
C=read();
while(C--){
int l,v,t;
l=read();
v=read();
t=read();
int L=v*t,R=l-v*t;
int ans=(max(R,L)-min(L,R)+1)/2;
if(ans<0)ans=-ans;
print(ans);
cout<<endl;
}
}这道题唯一的坑点就在于有可能 。