UVA10215 The Largest/Smallest Box ...计算几何
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10215 The Largest/Smallest Box ...计算几何相关的知识,希望对你有一定的参考价值。
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.
Fig: Cutting & Folding the Card
Given the width and height of the box, you will have to find the value of x for which the box has maximum and minimum volume.
Input
The input file contains several lines of input. Each line contains two positive floating-point numbers L (0 < L < 10000) and W (0 < W < 10000); which indicate the length and width of the card respectively.
Output
For each line of input you should give one line of output, which should contain two or more floatingpoint numbers separated by a single space. The floating-point numbers should contain three digits after the decimal point. The first floating point number indicates the value for which the volume of the box is maximum and then the next values (sorted in ascending order) indicate the values for which the volume of the box is minimum.
Sample Input
1 1
2 2
3 3
Sample Output
0.167 0.000 0.500
0.333 0.000 1.000
0.500 0.000 1.500
问题链接:UVA10215 The Largest/Smallest Box …
问题简述:给定一个W×L的卡片,减去4个x×x角,构成盒子。问盒子的最大和最小体积的x是多少?
问题分析:计算几何问题,不解释。
程序说明:需要注意精度。
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10215 The Largest/Smallest Box ... */
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
int main()
{
double l, w;
while (scanf("%lf%lf", &l, &w) == 2) {
double mx;
mx = (l + w - sqrt(w * w - w * l + l * l)) / 6.0;
if(l > w) l = w;
printf("%.3lf %.3lf %.3lf\\n", mx + EPS, 0.0, l / 2.0 + EPS);
}
return 0;
}
以上是关于UVA10215 The Largest/Smallest Box ...计算几何的主要内容,如果未能解决你的问题,请参考以下文章
UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)