[Analysis]\color{blue}{\texttt{[Analysis]}}[Analysis]
由于上下两块板相向移动,因此它们的相遇点是可以算出来的,而这个相遇点就是小球被夹逼所在的点。即小球被夹逼时的纵坐标可以算出来,同理小球被夹逼前需要的时间也是可以算出来的。这就是大名鼎鼎的夹逼定理!
对于横坐标,直接暴力模拟这个过程就可以了。注意需要特判小球追不上板的情况。小球追不上板有两种情况:
- 小球速度太慢了。这种情况小球永远追不上板。
- 时间不够了。小球理论上能追上,但剩余时间不够了。
总之按照题意模拟就可以了。
Code\color{blue}{\text{Code}}Code
cpp
void Main(){
cin>>T;
while (T--){
cin>>xb>>yb>>vx>>vy;
cin>>y_1>>y_2>>vy1>>vy2;
cin>>x_1>>x_2>>vx1>>vx2;
double ansy;
double meet_time=(y_2-y_1)/(vy1+vy2);
ansy=y_1+vy1*meet_time;
if (abs(vx1)<=eps&&abs(vx2)<=eps){
double period=2.0*(x_2-x_1)/vx;
meet_time=fmod(meet_time,period);
}
//左右两块板都不动,有周期可以简化
while (meet_time>=eps){
double time_cost=0;
if (vx>=eps){
if (vx2-vx>=eps)
time_cost=meet_time;//球追不上板
else{
time_cost=(x_2-xb)/(vx-vx2);
if (time_cost>meet_time)
time_cost=meet_time;//时间不够了
}
}//向右移动
else{
double vt=-vx;
if (vx1-vt>=eps)
time_cost=meet_time;
else{
time_cost=(xb-x_1)/(vt-vx1);
if (time_cost>meet_time)
time_cost=meet_time;
}
}
x_2+=vx2*time_cost;
x_1-=vx1*time_cost;
meet_time-=time_cost;
xb+=vx*time_cost;
vx=-vx;
}
printf("%.12lf %.12lf\n",xb,ansy);
}
return 0;
}