CodeForces - [ACM-ICPC Jiaozuo Onsite D]Keiichi Tsuchiya the Drift King(數學幾何)

題目鏈接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 aa inches and of length bb inches. He makes a right turn of a curve whose internal boundary is an arc with dd degrees in a circle with a radius of rr 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 ww 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 TT indicating the number of test cases which is up to 10410^4.

For each test case, the only one line contains four integers aa, bb, rr and dd, where 0<a,b,r<1000 \lt a,b,r \lt 100 and 0<d<1800 \lt d \lt 180.

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 10610^{-6}. Precisely speaking, assuming that your answer is aa and the jury’s answer is bb, your answer will be considered correct if abmax{1,b}106\frac{|a−b|}{max\{1,|b|\}}\le10−6.

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,那麼有以下兩種情況:

  1. 當小車轉過的角度dcd \geqslant c時,此時可以取到最大值l=(a+r)2+b2l = \sqrt{(a+r)^{2}+{b}^{2}}.
    在這裏插入圖片描述
  2. 當小車轉過的角度d<cd \lt c時,此時不能取到最大值w=(a+r)2+b2w = \sqrt{(a+r)^{2}+{b}^{2}}.
    此時我們可以通過下面那個紅色三角形來計算此時的最大值l=w×cos(cd)l = w \times cos(c - d).
    在這裏插入圖片描述
  • 注意角度要化成弧度值!!!

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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章