2021牛客暑期多校训练营1 - B - Ball Dropping - 题解

83 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

@TOC

2021牛客暑期多校训练营1 - B - Ball Dropping

传送门 Time Limit: 1 second Memory Limit: 262144K

题目描述

A standard sphere ball is falling in the air, and the center of the sphere is exactly on the centerline of an empty isosceles trapezoidal. The trapezoid is hanging horizontally under the sphere.

Please determine whether the ball will get stuck in the trapezoid or drop past the trapezoid.

输入描述:

The input contains four integers r,a,b,h(1r,a,b,h1000,a>b)r, a, b, h(1 \le r,a,b,h \le 1000, a > b), indicating the radius of the ball, the top base, the bottom base, and the height of the isosceles trapezoid.

It is guaranteed that 2rb,2r<a,2r<h2r \ne b, 2r < a, 2r < h.

输出描述:

Output 'Drop' if the sphere ball will drop past the empty trapezoid, otherwise output 'Stuck'.

If the answer is 'Stuck', please also calculate the stuck position(the height between the center of the sphere and the midpoint of the bottom base). Your answer is considered correct if its absolute or relative error does not exceed 10610^{-6}.

样例

样例一

输入

2 8 2 5

输出

Stuck
2.2206345966

样例二

输入

1 8 3 5

输出

Drop

题目大意

有个梯形东西,有个球往下掉,给你梯形的上底下底和高,以及球的半径。问球是否能掉下去,若掉不下去问球心距梯形下面的底面有多远。

解题思路

首先r<2br<2*b的话球肯定是要掉下去。 如果被卡住,被卡住的部分是与梯形侧面相切的。 画个图,梦回初中数学,从而解决这道题。


AC代码

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main()
{
    double r, a, b, h;
    cin >> r >> a >> b >> h;
    if (2 * r < b)
        puts("Drop");
    else
    {
        puts("Stuck");
        double g = sqrt(h * h + ((b - a) / 2) * ((b - a) / 2));
        double tan = (a - b) / (2 * h);
        double cos = h / g;
        double sin = (a - b) / (2 * g);
        double c = r * sin;
        double d = r * cos;
        double e = d - b / 2;
        double f = e / tan;
        double ans = c + f;
        // cout << ans << endl;
        printf("%.8lf\n", ans);
    }

    return 0;
}

同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…