B君要用一个表面积为S的圆锥将白山云包起来。
B君希望包住的白山云体积尽量大,B君想知道体积最大可以是多少。
注意圆锥的表面积包括底面和侧面。
Input
一行一个整数,表示表面积S。(1 <= S <= 10^9)
Output
一行一个实数,表示体积。
Input示例
8
Output示例
1.504506
C++的运行时限为:1000 ms ,空间限制为:131072 KB
示例及语言说明请按这里
思路:
这题一开始用二分求发现总是比答案少了,之后发现会不会是三分呢?之后网上搜三分,发现这很明显是一个凹函数啊,所以果断三分,之后就AC了。
AC代码:
#include<iostream>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
#define CRL(a) memset(a,0,sizeof(a))
#define QWQ ios::sync_with_stdio(0)
#define inf 0x3f3f3f3f
typedef unsigned long long LL;
typedef long long ll;
const int T = 1000000+50;
const int mod = 1000000007;
const double PI = 3.1415926535898;
const double esp = 0.00000001;
double s,ans;
double jugde(double x)
{
double L = s/(PI*x)-x;
double H = sqrt(L*L-x*x);
if(L<x)return -1;
double Ans = PI*x*x*H/3;
//if(L*PI*x+PI*x*x-s>esp)return -1;
if(Ans>=ans)ans = Ans;
return Ans;
}
int main()
{
#ifdef zsc
freopen("input.txt","r",stdin);
#endif
while(~scanf("%lf",&s))
{
double L=0,R=s,mid;
while(R-L>=esp)
{
mid = (R+L)/2;
double midmid = (mid+R)/2;
if(jugde(midmid)>jugde(mid)){
L = mid;
}
else {
R = midmid;
}
}
printf("%.6lf\n",ans);
}
return 0;
}