计算几何 A - Keiichi Tsuchiya the Drift King

A - Keiichi Tsuchiya the Drift King

题目链接:计蒜客

题解

分为两种情况:第一种:弯道完全可以容纳矩形;第二种:弯道不能完全容纳矩形。

第一种比较简单,勾股定理可以得出结果。

第二种需要留心,题目所求为弯道的宽度,按第一种方法所得的结果会相对偏大,需要减去多余的一小部分。

具体方法如图所示:
第一种情况
第二种情况

AC代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<vector>
#include<ctime>

using namespace std;
//#pragma GCC optimize(2)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9+7)
const double PI = (acos(-1.0));
typedef pair<int, int> P;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    int T;
    scanf("%d", &T);
    double a, b, r, d;
    while (T--) {
        scanf("%lf%lf%lf%lf", &a, &b, &r, &d);
        double dd = d * PI / 180.0;
        double w = sqrt(((a + r) * (a + r)) + b * b);
        double t = acos((a + r) / w);
        if (t - dd <= 0) {
            printf("%.12f\n", w - r);
        } else {
            double tt = (t - dd);
            double c = 2 * w * sin(tt / 2);
            tt = (PI - tt) / 2;
            double p = c * cos(tt);
            printf("%.12f\n", w - p - r);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45934120/article/details/108134526