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 a a inches and of length b b inches. He makes a right turn of a curve whose internal boundary is an arc with d d degrees in a circle with a radius of r r 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 w w 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 T T indicating the number of test cases which is up to 1 0 4 10^4 .

For each test case, the only one line contains four integers a a , b b , r r and d d , where 0 < a , b , r < 100 0 \lt a,b,r \lt 100 and 0 < d < 180 0 \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 1 0 6 10^{-6} . Precisely speaking, assuming that your answer is a a and the jury’s answer is b b , your answer will be considered correct if a b m a x { 1 , b } 10 6 \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. 当小车转过的角度 d c d \geqslant c 时,此时可以取到最大值 l = ( a + r ) 2 + b 2 l = \sqrt{(a+r)^{2}+{b}^{2}} .
    在这里插入图片描述
  2. 当小车转过的角度 d < c d \lt c 时,此时不能取到最大值 w = ( a + r ) 2 + b 2 w = \sqrt{(a+r)^{2}+{b}^{2}} .
    此时我们可以通过下面那个红色三角形来计算此时的最大值 l = w × c o s ( c d ) 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;
}
发布了808 篇原创文章 · 获赞 331 · 访问量 244万+

猜你喜欢

转载自blog.csdn.net/lzyws739307453/article/details/102255529