首页 > 其他 > 详细

Lightoj 1297 - Largest Box

时间:2015-08-16 16:43:58      阅读:199      评论:0      收藏:0      [点我收藏+]
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;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

Lightoj 1297 - Largest Box

原文:http://blog.csdn.net/grit_icpc/article/details/47702605

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!