链接:
https://vjudge.net/problem/LightOJ-1297
题意:
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.
思路:
三次函数。
求导,根据图像求二次函数的较小x解即可。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
int main()
{
int t, cnt = 0;
double l, w;
scanf("%d", &t);
while(t--)
{
printf("Case %d: ", ++cnt);
scanf("%lf%lf", &l, &w);
double res = (4*(l+w)-sqrt(16*(l+w)*(l+w)-4*12*(l*w)))/24.0;
printf("%lf
", res*(l-2*res)*(w-2*res));
}
return 0;
}