题意:给一个w*h(w<=h)的矩形。按照要求构造圆柱,求能够构造出来的最大圆柱体积。要求为:平行短边把矩形一分为二,用上面的那个矩形构造一个半径最大的圆作为圆柱的底,然后下半部分的矩形卷起来放到底上。当然要保证圈起来周长长于圆的周长咯。
思路:首先考虑圆的直径不为w。那么需要分别考虑拿下半个矩形的w还是h作为高。其中一个需要求导来算。然后考虑底圆的直径就是w,此时只能以w作为高,且需要满足
h-w>PI*w.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstdlib>
using namespace std;
#define INF 0x3fffffff
#define clc(s,t) memset(s,t,sizeof(s))
#define N 2000
#define PI acos(-1.)
int main(){
double w,h;
double s1,s2;
while(scanf("%lf %lf",&w,&h) && (int)(w+h)){
if(3*w < 2*PI*h)
s1 = w*w*(h*PI-w)/(4*PI*PI);
else
s1 = PI*h*h*h/27;
if(h<w*(PI+1))
s2 = PI*h*h*w/4/(PI+1)/(PI+1);
else
s2 = PI*w*w*w/4;
printf("%.3lf\n",max(s1,s2));
}
return 0;
}