BSG白山极客挑战赛-B君的圆锥(三分+数学)

wwwwodddd  (命题人)
基准时间限制:1 秒 空间限制:131072 KB 分值: 40
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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值