ZOJ3550 Big Keng(三分)

题意:给定一个立体的图形,上面是圆柱,下面是圆台,圆柱的底面半径和圆台的上半径相等,然后体积的V时,问这个图形的表面积最小可以是多少。(不算上表面)。一开始拿到题以为可以YY出一个结果,就认为它是圆锥,赛后才知道原来要三分三分再三分。 就是对上下体积三分,对上半径和下半径三分。至于为什么是凸的貌似也不怎么好想,但是我后来确实发现单纯的圆锥肯定取不到最大值,这题就当作是学习三分的技巧啦- -0

#pragma warning(disable:4996)

#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<vector>

#include<cmath>

#define ll long long

#define eps 1e-5

using namespace std;



double r1, r2, V;

double v1, v2;

double pi = acos(-1.0);



int dcmp(double x)

{

	return (x > eps) - (x < -eps);

}



double cal(double x)

{

	r2 = x;

	double H = v1 / (pi*r1*r1);

	double h = 3 * v2 / (pi*r1*r1 + pi*r2*r2 + pi*r1*r2);

	double ans = 0;

	double mother = sqrt((r2 - r1)*(r2 - r1) + h*h);

	ans = pi*(r1 + r2)*mother + 2 * pi*r1*H + pi*r2*r2;

	return ans;

}



double lr(double x)

{

	v1 = x; v2 = V - x;

	double l = 0, r = r1;

	while (dcmp(r - l)>0)

	{

		double m1 = l + (r - l) / 3;

		double m2 = l + 2 * (r - l) / 3;

		double x1 = cal(m1);

		double x2 = cal(m2);

		if (x1 < x2) r = m2;

		else l = m1;

	}

	return cal(l);

}



double vol(double x)

{

	r1 = x;

	double l = 0, r = V;

	while (dcmp(r-l)>0)

	{

		double m1 = l + (r - l) / 3;

		double m2 = l + 2 * (r - l) / 3;

		double x1 = lr(m1),x2 = lr(m2);

		if (x1 < x2) r = m2;

		else l = m1;

	}

	return lr(l);

}



double solve()

{

	double l = 0, r = 10*V;

	while (dcmp(r - l)>0){

		double m1 = l + (r - l) / 3;

		double m2 = l + 2 * (r - l) / 3;

		double x1 = vol(m1), x2 = vol(m2);

		if (x1 < x2) r = m2;

		else l = m1;

	}

	return vol(l);

}





int main()

{

	while (cin >> V)

	{

		double ans = solve();

		printf("%.6lf\n", ans);

	}

	return 0;

}

 

你可能感兴趣的:(ZOJ)