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)r, a, b, h(1 \le r,a,b,h \le 1000, a > b)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<h2r \ne b, 2r < a, 2r < h2r=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−610^{-6}10−6.
示例1
输入
2 8 2 5
2 8 2 5
输出
Stuck 2.2206345966
Stuck
2.2206345966
示例2
输入
1 8 3 5
1 8 3 5
输出
Drop
Drop
考点:平面几何,找关系式
思路:
先将梯形补成三角形,然后再利用相似和成比例求解
代码如下:
#include <bits/stdc++.h>
using namespace std;
double r,a,b,h;
double get(double r, double a, double b, double h){
double h1 = 2*r*1.0*sqrt(a*1.0/2*a/2+a*1.0*a*h*h/(a-b)/(a-b))/a-b*1.0*h/(a-b);
return h1;
}
int main(){
cin>>r>>a>>b>>h;
if(r<=b/2) cout<<"Drop"<<endl;
else{
printf("Stuck\n");
printf("%.20lf\n",get(r,a,b,h));//控制精度输出
}
return 0;
}