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

Ball Dropping

题目链接:

https://ac.nowcoder.com/acm/contest/11166/B

题目描述:

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.

示例1:

输入
2 8 2 5
输出
Stuck
2.2206345966

示例2:

输入
1 8 3 5
输出
Drop

解题思路:

三角形相似
在这里插入图片描述

代码如下:
#include<iostream>
#include<cmath>
using namespace std;

int main(){
	double r,a,b,h;
	double ans=0.0;
	double xiebian;  
	cin>>r>>a>>b>>h;
	if(r*2<=b)
		cout<<"Drop"<<endl;
	else{
		cout<<"Stuck"<<endl;
		xiebian = sqrt(h*h+(a-b)*(a-b)*0.25);  //大三角形的斜边
		ans = 2.0*h/(a-b)*(r/h*xiebian-b/2.0);  //相似
		printf("%.10lf\n",ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值