Time Limit: 2 second(s) | Memory Limit: 32 MB |
In the following figure you can see a rectangular card. The width of the card is W and length of the card is L and thickness is zero. Four (x*x) squares are cut from the four corners of the card shown by the black dotted lines. Then the card is folded along the magenta lines to make a box without a cover.
Given the width and height of the box, you will have to find the maximum volume of the box you can make for any value of x.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case starts with a line containing two real numbers L and W (0 < L, W < 100).
Output
For each case, print the case number and the maximum volume of the box that can be made. Errors less than 10-6 will be ignored.
Sample Input |
Output for Sample Input |
3 2 10 3.590 2.719 8.1991 7.189 |
Case 1: 4.513804324 Case 2: 2.2268848896 Case 3: 33.412886 |
题解:方程式列一下,因为是3次方,一看就是求极值的,但是注意范围是0,min(w,h)/2,三分写一下就过了。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
#define ZR (4*W+4*L)*(4*W+4*L)-48*W*L
using namespace std;
const int INF=0x3f3f3f3f;
double L,W;
double js(double x){
return x*(L-*x)*(W-*x);
}
double sf(double l,double r){
double mid,mm;
while(r-l>1e-){
mid=(l+r)/;
mm=(mid+r)/;
if(js(mid)>=js(mm))r=mm;
else l=mid;
}
return mid;
}
int main(){
int T,flot=;
scanf("%d",&T);
while(T--){
scanf("%lf%lf",&L,&W);
double x=sf(,min(L,W)/);
// printf("%f\n",x);
printf("Case %d: %lf\n",++flot,js(x));
}
return ;
}