题目:一个上面开口的矩形的牛奶盒,与底面桌子有一定的夹角(有一条底边)和桌面相切,求盒子中牛奶的体积。
分析:计算几何、简单题。按照界面计算乘以宽度即可。
处理时按照图示的两种情况即可,分界条件 tanθ 与 h/l 比较即可。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double p = acos(-1.0);
double l,w,h,t;
while ( ~scanf("%lf%lf%lf%lf",&l,&w,&h,&t) ) {
//判断剩余牛奶的形状
if ( tan(t*p/180.0) < h/l )
printf("%.3lf mL\n",w*l*h-0.5*w*l*l*tan(t*p/180.0));
else printf("%.3lf mL\n",0.5*h*h*w/tan(t*p/180.0));
}
return 0;
}