| 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 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).
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/grit_icpc/article/details/47702605