/* 返回顶部 */

POJ3737 UmBasketella

gate

用时:20min(看题解了)

题目大意:
给定圆锥的表面积\(S\),求这个圆锥的最大体积\(V\),以及此时它的高\(h\)与底面半径\(r\)

\(S = \pi rl+\pi r^2\)
\(h = \sqrt{l^2-r^2}\)
\(V = \dfrac{1}{3}\pi r^2 h\)
\(V = \dfrac{1}{3}\sqrt{S^2 r^2-2\pi Sr^4}\)

\(V\)是关于\(r\)的一个单峰函数,三分\(r\)求解即可。

注意:
\(\pi = acos(-1.0)\)
因为\(cos(\pi) = -1\),所以\(arccos(-1) = \pi\)
注意这里要写\(-1.0\),否则会\(CE\)

\(code\)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#define MogeKo qwq
using namespace std;

const double Pi = acos(-1.0);
const double eps = 1e-6;

double S,L,R,l,h,V;

double calc(double r){
    l = (S/Pi - r*r) / r;
    h = sqrt(l*l - r*r);
    V = Pi * r*r * h / 3.0;
    return V;
}

int main(){
    while(~scanf("%lf",&S)){
        L = 0,R = S;
        while(R-L >= eps){
            double d = (R-L)/3.0;
            double m1 = L+d;
            double m2 = R-d;
            if(calc(m1) < calc(m2)) L = m1;
            else R = m2;
        }   
        printf("%.2lf\n%.2lf\n%.2lf\n",calc(L),h,L);
    }
    return 0;
}
posted @ 2020-07-09 15:17  Mogeko  阅读(149)  评论(0编辑  收藏  举报