Gym 102028D Keiichi Tsuchiya the Drift King(2018 ICPC 焦作站 D 题) 计算几何

去年暑假集训了两个月就去了焦作,这个题一直卡着到最后也没做出来,很遗憾的在人生中第一场 ICPC 比赛打了铁。当时也没有补题的习惯,这个题知道了大致做法后就放过了。今年准备银川赛区,翻出了往年的比赛真题做一下,又碰到了这道题,虽然很水,但还是想写个博客纪念一下,毕竟银川可能是参加的最后一场 ICPC 比赛了,希望不会留下遗憾!!!

题目链接

D. Keiichi Tsuchiya the Drift King

time limit per test:2.0 s        memory limit per test:1024 M

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 10^4.

For each test case, the only one line contains four integers a, br and d, where 0 < ab< 100 and 0 < < 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  \frac{\left | a-b \right |}{max\left \{ 1,\left | b \right | \right \}}\leqslant 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

题意

给定一辆小车长宽分别为 b,a,轨道的圆弧部分半径为 r,圆弧对应的角度为 d,求出小车能通过轨道的最小轨道宽度 w。

分析

我们先考虑临界情况,因为要求轨道宽度,而小车长宽和弯道半径都是给定的,所以临界情况之和弯道圆弧对应的圆心角有关了。我们假设这个临界角叫 res,在题目所给 d 大于 res 时,小车通过轨道需要的轨道宽度是一定的,而 d 小于 res 时,需要的轨道宽度就和 d 成函数关系了。那么这个临界情况是什么呢,就是下图所示。

在这种情况下,小车恰好能全部进入弯道,因此一旦 d 大于这种情况下的圆心角,则轨道宽度是一定的。

若是 d 小于临界条件,则如下图所示。

为了方便描述我给各个节点标上字母,此时 d 为 角AOE,我们可以把它看成 角DOE 旋转了一下,到了 角AOC 的位置,这便是第二种情况:小车无法全部进入轨道。很明显,角EOC = 角AOD = res - d,此时轨道的最小宽度为 BO 的长度,而我们知道 CO = EO,所以 BO = CO * cos( res - d )。

写代码时要注意 cmth 头文件中,三角函数均为弧度运算。弧度 = 角度 * PI / 180.

代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define PI acos(-1.0)
int main()
{
    int T;
    double a, b, r, d;
    scanf("%d", &T);
    while(T--){
        scanf("%lf %lf %lf %lf", &a, &b, &r, &d);
        d = d * PI / 180;
        double res = atan(b / (a + r));
        if(d >= res){
            printf("%.12f\n", sqrt((a + r) * (a + r) + b * b) - r);
        }
        else {
            printf("%.12f\n", sqrt((a + r) * (a + r) + b * b) * cos(res - d) - r);
        }
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值