題目鏈接:https://codeforces.com/gym/102028/problem/D
Time limit: 2.0 s Memory limit: 1024 MB
Problem Description
Drifting is a driving style in which the driver uses the throttle, brakes, clutch, gear shifting and steering input to keep the car in a state of oversteer while manoeuvring from turn to turn. As a sport, the drifting was first practised in Japan in the late 80s before gaining worldwide popularity in the decade that followed.
Keiichi Tsuchiya is a Japanese driver who is better known as the Drift King. He played an important role in popularizing the art of drifting. This pioneer inspired many successful drivers. He appeared in the movie The Fast and the Furious: Tokyo Drift and he is often employed on various movie sets as both driver and stunt coordinator. Keiichi Tsuchiya’s talent in the drifting is especially true of his big stunt, the ultimate drifting.
Here is what he could do. The drift car he drives is shaped like a rectangular box of width inches and of length inches. He makes a right turn of a curve whose internal boundary is an arc with degrees in a circle with a radius of inches. As a super-skilled driver, he maintains his car to keep the contact and tangency at the internal boundary. That is, the right front corner of the car should always run along the internal boundary and the direction of the car body should always be tangential to the internal boundary.
We have measured that the straightaways before and after the curve are long enough, and the width of the lane is invariable. As what we meet in real life, if a lane has a fixed width, for each point of its one side, the distance to the nearest point of the other side is exactly its width. Now you are asked to calculate the minimal width of the lane so that the Drift King could drive throughout the curve without drifting out of the lane.
Input
The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .
For each test case, the only one line contains four integers , , and , where and .
Output
For each test case, output a line containing the minimal width (in inches) of the lane with an absolute or relative error of at most . Precisely speaking, assuming that your answer is and the jury’s answer is , your answer will be considered correct if .
Example
Input
4
1 2 2 120
1 2 2 60
1 2 2 30
1 2 2 15
Output
1.605551275464
1.605551275464
1.598076211353
1.415415569072
Problem solving report:
Description:給出寬爲a,長爲b的車,有一條半徑爲r,角度爲d的拐彎軌道,讓你求出軌道的寬度,滿足儘可能的小。
Problem solving:最小的l取決小車通過彎道的過程中小車的角距離圓心最遠的時刻,即小車和彎道相切且切點與小車的一個角重合時,對應的角就是距離最遠的位置,如下圖:
設r與a初值時,r+a與b形成的直角三角形靠近圓心的角記作c,那麼有以下兩種情況:
- 當小車轉過的角度時,此時可以取到最大值.
- 當小車轉過的角度時,此時不能取到最大值.
此時我們可以通過下面那個紅色三角形來計算此時的最大值.
- 注意角度要化成弧度值!!!
Accepted Code:
/*
* @Author: lzyws739307453
* @Language: C++
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const double eps = 1e-8;
const double PI = acos(-1);
int sgn(double x) {
return x > eps ? 1 : x < -eps ? -1 : 0;
}
int main() {
int t;
double a, b, r, d, l, Ang;
scanf("%d", &t);
while (t--) {
scanf("%lf%lf%lf%lf", &a, &b, &r, &d);
l = sqrt(b * b + (a + r) * (a + r));
d = d / 180 * PI;
Ang = atan2(b, (a + r));
if (sgn(Ang - d) > 0)
l = l * cos(Ang - d);
printf("%.12f\n", l - r);
}
return 0;
}