Keiichi Tsuchiya the Drift King
Posted Jozky86
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keiichi Tsuchiya the Drift King相关的知识,希望对你有一定的参考价值。
Keiichi Tsuchiya the Drift King
题意:
给定一辆小车长宽分别为 b,a,轨道的圆弧部分半径为 r,圆弧对应的角度为 d,求出小车能通过轨道的最小轨道宽度 w。
题解:
我们考虑小车处于什么状态会使弯道最宽,就是小车和弯道相切并且切点和小车的一个角重合的时候,此时对应的角就是距离最远的位置,这种情况w可以通过勾股定理得到,w = sqrt((a+r)2 + b2 )
但是还有另一种情况,我们设上面那个情况的角度为d,当角度小于d时,情况就不一样。如图,此时我们求出的w是斜边,而非我们想要的水平边,但是可以通过w反求ans,α=res-d,cos(α)=ans/w,这样就得到ans
代码中atan(b / (a + r)),atan可以求res的角度
代码:
#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;
}
以上是关于Keiichi Tsuchiya the Drift King的主要内容,如果未能解决你的问题,请参考以下文章