您的位置:首页 > 其它

lightOJ 1297 - Largest Box 【数学题】

2015-11-08 18:58 267 查看
1297 - Largest Box



PDF (English)StatisticsForum
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

PROBLEM SETTER: SHAHRIAR MANZOOR
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)

思路:

由题意知体积等于(L-2*x)*(W-2*x)*x的最大值,且最大值肯定存在,那么就直接对它求导,然后由一元三次方程的图像可以知道,应该取另它等于0得到的较小的解,(这个不用考虑边界100,因为50取不到,所以就不可能是最大值的x的取值),只考虑一个就行了!不用想太多,就只找一个极大值(也就是最大值)就行了!

代码如下:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
double l,w;
double maxn;
double V(double x)
{
double v=(l-2*x)*(w-2*x)*x;
return v;
}
int main()
{
int T;
scanf("%d",&T);
int N=T;
while(T--)
{
scanf("%lf%lf",&l,&w);
double x=(4*(w+l)-sqrt(16*(w+l)*(w+l)-4*12*(w*l)))/24.0;
printf("Case %d: ",N-T);
printf("%lf\n",V(x));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: