lightoj 1297 - Largest Box 【函数最值】

1297 - Largest Box
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的最大值,保证存在解。


直接求导后找点就可以了,一开始想复杂了。



AC代码:


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN 50
#define MAXM 50000000
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
int main()
{
    int t, kcase = 1;
    Ri(t);
    W(t)
    {
        double L, W;
        Rf(L); Rf(W);
        double l = 0, r = min(L, W) / 2;
        double a = 12, b = -(4*L+4*W), c = L*W;
        double x1 = (-sqrt(b*b-4*a*c) - b) / 2 / a;
        double x2 = (sqrt(b*b-4*a*c) - b) / 2 / a;
        double ans;
        //if(x1 > l && x1 < r)
            ans = (L-2*x1) * (W-2*x1) * x1;
        //else
            //ans = ;
        printf("Case %d: %.7lf\n", kcase++, ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值