题意
给出一个圆锥的表面积,求最大体积。
思路
显然,得到底面积的半径后,一切都能得到。在我们慢慢延长半径时,发现不满足线性,而是单峰函数。故三分。
圆锥复习
Code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define cf int _o_o_;cin>>_o_o_;for (int Case = 1; Case <= _o_o_;Case++)
#define SZ(x) (int)(x.size())
inline void _A_A_();
signed main() {_A_A_();return 0;}
// #define int long long
int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 210, M = 5010;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
double area;
double check(double mid) {
double left = area - acos(-1) * mid * mid;
double muxian = left / acos(-1) / mid;
double h = sqrtl(muxian*muxian - mid * mid);
return acos(-1) * mid * mid * h / 3.0;
}
inline void _A_A_() {
while (~scanf("%lf", &area)) {
double l = 0.00001, r = sqrtl(area / acos(-1));
while (r - l > eps) {
double len = r - l;
double mid1 = l + len / 3.0, mid2 = r - len/3.0;
if (check(mid1) > check(mid2)) {
r = mid2;
}
else l = mid1;
}
double left = area - acos(-1) * l * l;
double muxian = left / acos(-1) / l;
double h = sqrtl(muxian*muxian - l * l);
double vol = acos(-1) * l * l * h / 3.0;
printf("%.2lf\n%.2lf\n%.2lf\n", vol, h, l);
}
}
标签:double,POJ,3.0,3737,include,mid2
From: https://www.cnblogs.com/FanWQ/p/16867291.html