| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
有谁帮忙看看了老WA? 多谢了/*
为什么用二分写不可以啊,难道是精度的问题嘛,测了些数据感觉也没错,真的无语!不过感觉上是精度出了问题,还是本来就不能用二分?有大牛能解释下么?后来算 了下,可以直接算出最大的值,
r=sqrt(s/pi)/2;
L=s/pi/r-r;
h=sqrt(L*L-r*r);
V=1.0/3*pi*r*r*h;
那二分不知道哪错了?
*/
#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
#define EXP 1e-8
double funv(double R,double S)
{
double L;//母线L=sqrt(R^2+h^2);
double h;
double V;
L=S/PI/R-R;
h=sqrt(L*L-R*R);
V=PI*R*R*h/3.0;
return V;
}
int main()
{
double s,v,h,left,right,mid,L;
while(scanf("%lf",&s)!=EOF)
{
left=0.0;right=sqrt(s/PI);
while(left<right)
{
mid=(left+right)/2.0;
L=s/PI/mid-mid;
h=sqrt(L*L-mid*mid);
v=funv(mid,s);
if(funv(mid-EXP,s)>funv(mid,s))
right=mid;
else
left = mid;
if(right-left<EXP)
{
printf("%.2lf\n",funv(mid,s));
printf("%.2lf\n",h);
printf("%.2lf\n",mid);
break;
}
}
}
return 0;
}
/*
10000
66490.38
79.79
28.21
100.5465
67.04
8.00
2.83
1231.545464
2873.65
28.00
9.90
4564.575464
20504. 01
53.91
19.06
4565.1545
20508.88
53.91
19.06
*/
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator