hdu 5954 -- Do not pour out(积分+二分)
2018-06-17 21:49:18来源:未知 阅读 ()
![新老客户大回馈,云服务器低至5折](/info/templets/default/images/760x90_D.jpg)
题目链接
The height of liquid level in the cup is d (0 ≤ d ≤ 2). When you incline the cup to the maximal angle such that the liquid inside has not been poured out, what is the area of the surface of the liquid?
![](/info/upload/20180618/20e5ht1y3r2.png)
![](/info/upload/20180618/ow0oazrk3jm.png)
![](/info/upload/20180618/nojldfsq1g3.jpg)
求出真实的mid以后,那么就可以求出水面的面积了。
如上图所示利用二分求出的mid得 len=sqrt(2*2+mid*mid),设水面与杯底的一个交点为(x,h),h=sqrt(1-(1-mid)*(1-mid)) (由杯底水面交线所在圆很容易求出 h ),那么len=a-x 且x^2/a^a+h^2/b^2=1 ,解上面两个方程 求得a= a=len/(1+(flag表示正负)flag*sqrt(1-h*h)),x=a-len 可以发现mid<1时水面为小半个椭圆,这时x>0,所以flag<0,反之mid>1时,水面为大半个椭圆,这时x<0,flag>0 。
现在椭圆方程已求出,X范围(x,a)(不是完整的椭圆),所以需要积分,如下图所述:
面积终于求出来了,太惊喜了!
那么现在就该上代码了:
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; const double PI=acos(-1); const double eps=1e-12; double cal2(double x) { double sum=x+sin(2*x)/2; return sum; } double area(double a,double x) { double sum=cal2(0.5*PI); sum=sum-cal2(asin(x/a)); return sum*a; } double cal(double x) { double ans=sin(x)-sin(x)*sin(x)*sin(x)/3-x*cos(x); return ans; } double getV(double mid) { double V=cal(acos(1))-cal(acos(1-mid)); V=V*(-2)/mid; return V; } int main() { int T; cin>>T; while(T--) { double d; scanf("%lf",&d); if(d>1) { double h=2*d-2; double a=sqrt(4+(2-h)*(2-h))/2; printf("%.5f\n",PI*a); continue; } double l=0.0,r=2.0; for(int i=0;i<50;i++) { double mid=(l+r)/2; //double du=acos(1-mid); //double S=du-sin(du)*(1-mid); double V=getV(mid); if(fabs(V-PI*d)<eps) break; if(V>PI*d) r=mid; else l=mid; } double mid=l; if(mid==0.0) mid=eps; int flag=1; if(mid<1) flag=-1; double len=sqrt(mid*mid+4); double h=sqrt(1-(1-mid)*(1-mid)); double a=len/(1+flag*sqrt(1-h*h)); double x=a-len; double res=area(a,x); printf("%.5f\n",res); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:c++趣味之难以发现的bug
- HDU-2955-Robberies(0-1背包) 2020-03-30
- C++ non-const lvalue reference cannot bind to a temporar 2020-03-09
- SGU 132 Another Chocolate Maniac 2020-03-06
- hdu1455 拼木棍(经典dfs) 2020-02-29
- qt连接mysql报错:QSqlDatabase: QMYSQL driver not loaded 2020-02-29
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash