admin管理员组文章数量:1794759
【数学
前言
这道题虽然比较水,但感觉比较有意思啊~特地写个博客纪念一下
而且通过这道题,我发现了C++里面居然自带三角函数和反三角函数,很有收获
这个知识是百度时偶然看到的,感觉很有用,以后遇到相关题目就可以直接拿来用啦
题目
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400 points
Problem Statement
Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a cm
and whose height is b cm
. (The thickness of the bottle can be ignored.)
We will pour x cm3
of water into the bottle, and gradually tilt the bottle around one of the sides of the base.
When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.
Constraints
- All values in input are integers.
- 1≤a≤100
- 1≤b≤100
- 1≤x≤a^2*b
Input
Input is given from Standard Input in the following format:a,b,x
Output
Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^−6.
Sample Input 1
2 2 4
Sample Output 1
45.0000000000
This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45
degrees.
Sample Input 2
12 21 10
Sample Output 2
89.7834636934
This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.
Sample Input 3
3 1 8
Sample Output 3
4.2363947991
This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.
题目大意
给你一个底面积为 a * a,高为 b 的矩形柱体,并向杯中倒入体积为x的水
现沿杯子底部的一条棱将杯子倾斜,问水不溢出时,杯子的最大的倾斜角度
分析
首先提炼模型,大致可分为以下三种(或两种,x=1/2v的情况可归于其他的情况)
设水的体积为x,杯子体积为v,v=a*a*b
1.x>1/2v
2.x=1/2v
3.x<1/2v
立体形状大致如下:
1.当x>=1/2v时,空白处体积 v ' = v - x,v ' =1/2( a * a * t ),
所以 t = 2 * ( v - x ) / ( a * a ) , tanθ = t / a
2.当x<1/2v时,水的体积 x = 1/2( t * a * b )
所以 t = 2 * x / ( a * b ) , tanθ = b / t
知道了θ角的正切值,再用“反正切值”算出角度即可,用法详情参见代码
注意:函数中计算使用的为弧度制,最后要转化为角度
代码
#include<cstdio>
#include<cmath>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
double t,tang,pans,ans,pi=3.141592654;
int a,b,x,v;
int main()
{scanf("%d%d%d",&a,&b,&x);v=a*a*b;if(x>=v/2){t=(double)(2*v-2*x)/(a*a);tang=(double)t/a;pans=atan(tang);ans=(double)pans*180/pi;}else if(x<v/2){t=(double)2*x/(a*b);tang=(double)b/t;pans=atan(tang);ans=(double)pans*180/pi;}printf("%.7f\n",ans);return 0;
}
本文标签: 数学
版权声明:本文标题:【数学 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1692784785a195004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论