Keiichi Tsuchiya the Drift King(Gym-102028D)

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 T indicating the number of test cases which is up to 104.

For each test case, the only one line contains four integers a, b, r and d, where 0<a,b,r<100 and 0<d<1800<d<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 10−6. Precisely speaking, assuming that your answer is aa and the jury's answer is bb, your answer will be considered correct if |a−b|max{1,|b|}≤10−6

Examples

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

题意:如上图,给出 a、b、d、r,求最小的 w

思路:

思路来源:https://blog.csdn.net/holly_Z_P_F/article/details/85110163

最小的 w 取决小车通过弯道的过程中小车的角距离圆心最远的时刻,即小车和弯道相切且切点与小车的一个角重合时,对应的角就是距离最远的位置

设 r 与 a 初值时,r+a 与 b 形成的直角三角形靠近圆心的角记作 t1,那么有两种情况:

当 t1<d 时,有:maxw=sqrt((a+r)^2+b^2)-r

当 t1>d 时,橙色线和绿色线相等,构成了一个扇形,形成的圆心角 t2=t1-d,此时利用弦长公式可求出红色的弦长 L,而由于橙线和绿线相等,可以得到弦长 L 与橙线的夹角 t3,从而得出多余的一小段 p 的长度,那么最终答案就是 maxw-p-r

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<LL,LL>
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        double a,b,r,d;
        scanf("%lf%lf%lf%lf",&a,&b,&r,&d);

        double maxw=sqrt( (r+a)*(r+a)+ b*b );//勾股定理

        double dc=d*PI/180;//角度转弧度
        double t1=acos((a+r)/maxw);//最远点形成的角度
        if((dc-t1)>0) {
            printf("%.12f\n",maxw-r);
        }
        else {
            double t2=t1-dc;
            double L=2*maxw*sin(t2/2);//圆心角所对弦长
            double t3=(PI-t2)/2;
            double p=L*cos(t3);
            printf("%.12f\n",maxw-p-r);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值