Keiichi Tsuchiya the Drift King
生活随笔
收集整理的這篇文章主要介紹了
Keiichi Tsuchiya the Drift King
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Keiichi Tsuchiya the Drift King
題意:
給定一輛小車長寬分別為 b,a,軌道的圓弧部分半徑為 r,圓弧對(duì)應(yīng)的角度為 d,求出小車能通過軌道的最小軌道寬度 w。
題解:
我們考慮小車處于什么狀態(tài)會(huì)使彎道最寬,就是小車和彎道相切并且切點(diǎn)和小車的一個(gè)角重合的時(shí)候,此時(shí)對(duì)應(yīng)的角就是距離最遠(yuǎn)的位置,這種情況w可以通過勾股定理得到,w = sqrt((a+r)2 + b2 )
但是還有另一種情況,我們?cè)O(shè)上面那個(gè)情況的角度為d,當(dāng)角度小于d時(shí),情況就不一樣。如圖,此時(shí)我們求出的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; }總結(jié)
以上是生活随笔為你收集整理的Keiichi Tsuchiya the Drift King的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用Mac电脑看小说,阅读器软件怎么选
- 下一篇: DNS协议与请求