D. Keiichi Tsuchiya the Drift King
题目大意:
给出宽为a,长为b的车,有一半径为r,角度为d的拐弯弯道,求出最小宽度且车的右上角始终为车与圆的相切点。
解题思路:
-
临界情况如下图,此时 θ = a r c t a n ( b / ( a + r ) ) \theta=arctan(b/(a+r)) θ=arctan(b/(a+r)),所以当所需转过的角度大于 θ \theta θ
时,答案始终为: s q r t ( ( a + r ) 2 + b 2 ) − r sqrt((a+r)^2+b^2)-r sqrt((a+r)2+b2)−r
-
当 d < θ d<\theta d<θ时,如下图,只要求出红色线的长度-圆半径即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef double db;
const db pi = acos(-1);
db sqr(db x) {return x * x;}
int main() {
int _;
cin >> _;
while (_--) {
db a, b, r, d;
cin >> a >> b >> r >> d;
db theta = d / 180 * pi, alpha = atan(b / (a + r));
db l = sqrt(sqr(b) + sqr(a + r));
if (theta >= alpha) {
cout << fixed << setprecision(8) << l - r << endl;
}
else {
cout << fixed << setprecision(8) << l * cos(alpha - theta) - r << endl;
}
}
}