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

## 题目描述

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(1≤r,a,b,h≤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 $2r≠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 $10^{-6}$ .

2 8 2 5

Stuck
2.2206345966

1 8 3 5

Drop

## 题解

1. 首先能掉下去肯定是 $2r<b$ 的情况
2. 主要是不能掉下去的情况，让你求圆心到梯形底部距离（下图中x的值），推一下公式，推理如下：

橙色字的公式推理可以看这个博客：https://blog.csdn.net/wkl7123/article/details/46288745

## 代码

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include<cmath>
using namespace std;
const int maxn = 2e3 + 10;

double r, a, b, h;
int main() {
cin >> r >> a >> b >> h;
if (2 * r < b) cout << "Drop";
else {
cout << "Stuck" << endl;
double sin = h / sqrt(h * h + ((a - b) / 2) * ((a - b) / 2));
double cos = (a - b) / 2 / sqrt(h * h + ((a - b) / 2) * ((a - b) / 2));
double m = (r * sin - b / 2) / cos;
double l = sqrt((b / 2) * (b / 2) + m * m + b * m * cos);
double x = sqrt(r * r + l * l - 2 * r * r * sin * sin +
2 * r * sqrt((l * l - r * r * sin * sin) * cos * cos));
printf("%.10lf", x);
}
return 0;
}