Lightoj 1297 - Largest Box

Memory Limit: 32 MB

In the following figure you can see a rectangular card. Thewidth of the card isW and length of the card is L and thicknessis zero. Four(x*x) squares are cut from the four corners of the cardshown by the black dotted lines. Then the card is folded along the magentalines to make a box without a cover.

Given the width and height of the box, you will have to findthe maximum volume of the box you can make for any value ofx.

Input

Input starts with an integer T (≤ 10000),denoting the number of test cases.

Each case starts with a line containing two real numbers LandW (0 < L, W < 100).

Output

For each case, print the case number and the maximum volumeof the box that can be made. Errors less than10-6 will beignored.

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



题目大意:求矩形的最大体积。



#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL double
using namespace std;

double f(double l,double w)//必然和求导数有关,那么求完导数怎么求MAX V呢
{
    double a,b,c,k;
    a=12.0;b=-4.0*(l+w);c=l*w;//MAX V与所截得的X长度有关系,所以先求出X的值就解决了。求完导数剩下的一元二次方程,当根为0时取得极值。
     k=-b-sqrt(b*b-4*a*c);//这里取得左根
     k/=2*a;//K即为所求的X值。x=-b+-(sqrt(b^2-4ac))/2a;
     return  (l-2*k)*k*(w-2*k)  ;
}

int main()
{
    LL l,w,c,i,x,y;
    int cla;
    scanf("%lld",&cla);
    for(int gr=1; gr<=cla; gr++)
    {
        printf("Case %d: ",gr);
        scanf("%lf %lf",&l,&w);
        printf("%lf\n",f(l,w));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值