[kuangbin]数学训练一K - Largest Box 霖行

Posted 霖行

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[kuangbin]数学训练一K - Largest Box 霖行相关的知识,希望对你有一定的参考价值。

【[kuangbin]数学训练一】K - Largest Box 【霖行】

题目:

K - Largest Box

In the following figure, you can see a rectangular card. The width of the card is W, 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 red lines to make a box without a cover.

Box

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

3
2 10
3.590 2.719
8.1991 7.189

Sample Output

Case 1: 4.513804324
Case 2: 2.2268848896
Case 3: 33.412886

题目大意:

有一个长为L宽为W的矩形,在矩形的四角上分别截去一个边长为x的正方形,然后拼成一个盒子。问盒子最大体积。

题目分析:

利用逼近法,不断找出体积较大的x值,直到误差允许。

代码:

#include<iostream>
using namespace std;

double V(double L, double W, double X)
{
	return W * L * X - 2 * X * X * (W + L) + 4 * X * X * X;
}

int main()
{
	int T; cin >> T;
	for (int i = 1; i <= T; i++)
	{
		double L, W; cin >> L >> W;
		double l = 0, r = min(L, W) / 2, mid, mm;
		while (r - l >= 0.000000001)
		{
			mid = (l + r) / 2;
			mm = (mid + r) / 2;
			if (V(L, W, mid) >= V(L, W, mm))
				r = mm;
			else
				l = mid;
		}
		printf("Case %d: %lf\\n", i, V(L, W, mid));
	}
	return 0;
}

以上是关于[kuangbin]数学训练一K - Largest Box 霖行的主要内容,如果未能解决你的问题,请参考以下文章

acm数学(待续)

蓝桥杯——算法训练之乘积最大

专题训练——[kuangbin带你飞]最短路练习

kuangbin带我飞(基础dp)

Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

kuangbin专题每日一题 棋盘问题 POJ-1321