LightOJ 1297: Largest Box【数学】

C - Largest Box
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  LightOJ 1297
Appoint description:  System Crawler  (2015-11-04)

Description

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

3

2 10

3.590 2.719

8.1991 7.189

Sample Output

Case 1: 4.513804324

Case 2: 2.2268848896

Case 3: 33.412886

AC-code:

#include<cstdio>
#include<cmath>
int main()
{
	int t,i;
	double w,l,a,b,x1,x2,fx,fy;
	scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%lf%lf",&w,&l);
		a=sqrt(16*(w+l)*(w+l)-48*w*l);
		x1=(4*(w+l)-a)/24;
		x2=(4*(w+l)-a)/24;
		fx=(w-2*x1)*(l-2*x1)*x1;
		fy=(w-2*x2)*(l-2*x2)*x2; 
		if(fx<fy)
			fx=fy;
		printf("Case %d: %lf\n",i,fx);
	}
	return 0;
}


你可能感兴趣的:(LightOJ 1297: Largest Box【数学】)