Keiichi Tsuchiya the Drift King (几何题)

题目:

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 inches and of length b inches. He makes a right turn of a curve whose internal boundary is an arc with d degrees in a circle with a radius of 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 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<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 a and the jury’s answer is b, your answer will be considered correct if |a−b|max{1,|b|}≤10−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

在这里插入图片描述
分情况讨论,找到极限的地方,主要是d与tan(b/(a+r))的关系来判断
下图是相等时的情况
在这里插入图片描述
在这里插入图片描述
红色是一种情况,此时d<tan(b/(a+r));绿色是另一种情况,此时d>tan(b/(a+r))

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1);

inline ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main(){
    int t=read();
    double a,b,r,d;
    while(t--){
        scanf("%lf%lf%lf%lf",&a,&b,&r,&d);
        double aa=atan(a/b)+pi/2.0;
        double bb=sqrt(a*a+b*b);
        double cc=sqrt(r*r+bb*bb-2*r*bb*cos(aa));
        double tt=b/(a+r);
        if(tt<tan(d*pi/180.0)||tt>0&&tan(d*pi/180.0)<0){
            double cc=sqrt(r*r+bb*bb-2*r*bb*cos(aa));
            printf("%.12f\n",cc-r);
        }else{
            double cc=a*cos(d*pi/180.0)+b*sin(d*pi/180.0)+r*cos(d*pi/180.0);
            printf("%.12f\n",cc-r);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值