1. 程式人生 > >D - Keiichi Tsuchiya the Drift King Gym - 102028D (幾何)

D - Keiichi Tsuchiya the Drift King Gym - 102028D (幾何)

題目連結:https://cn.vjudge.net/contest/275150#problem/D

題目大意: 問你能滿足那個矩形可以順利通過的條件,然後求出最小的w

具體思路:首先,我們應該將情況分成兩種.

第一種,這個矩形可以完全的放在彎道中,這是第一種情況,

第二種,這個矩形不能完全放在彎道中,也就是說當上面都已經到達出去彎道的邊界了,然而下面還沒有完全的進來,這是第二種情況.

AC程式碼:

#include<iostream>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<cmath>
using namespace std;
# define inf 0x3f3f3f3f
# define ll long long
# define pi acos(-1.0)
const int mod = 1e9 ;
const int maxn = 100000+100;
int main()
{
    int T;
    scanf("%d",&T);
    double a,b,r,d;
    while(T--)
    {
        scanf("%lf %lf %lf %lf",&a,&b,&r,&d);
        d= d / 180.0 * pi;
        double h1 = a * sin(d) + r * sin(d) ;
        double h2 = b * cos(d);
        h2-=h1;
        double ans=0;
        if(h2 <= 0 )
        {
            ans = sqrt( (a + r) * (a + r) + b * b)-r;
        }
        else ans= a * cos(d) + b * sin(d) + r * cos(d) - r;
        printf("%.9lf\n",ans);
    }
    return 0;
}