UVA 10215 - The LargestSmallest Box ...
来源:互联网 发布:1024程序员节 编辑:程序博客网 时间:2024/05/23 22:09
很显然,盒子体积最大值要通过求导,然后解出最大值,最小只有两个,一个是0,即一点也不剪,另一个就是矩形长宽较短的那条边的一半,这样两种情况体积都是0,当然最小,但是由于求极大值极小值过程需要用到除法,所以要加上精度控制,(一开始没加WA了)
code:
#include<cstdio>
#include<cmath>
#define eps 1e-7
int main()
{
double l, w, min, max;
while(scanf(\"%lf%lf\",&l,&w)!=EOF)
{
if(w>l)
{
double tmp=w;
w=l;
l=tmp;
}
min=(l+w-sqrt(l*l+w*w-l*w))/6;
max=(l+w+sqrt(l*l+w*w-l*w))/6;
double ans1=(l-2*min)*(w-2*min)*(min);
double ans2=(l-2*max)*(w-2*max)*(max);
double ans;
if(ans1>ans2)
ans=min;
else
ans=max;
printf(\"%.3lf 0.000 %.3lf\\n\",ans+eps,(w/2.0)+eps);//一定要加精度控制
}
return 0;
}
- UVA 10215 - The LargestSmallest Box ...
- [uva] 10215 - The Largest/Smallest Box ...
- UVa 10215 - The Largest/Smallest Box ...
- UVa Problem 10215 The Largest/Smallest Box... (最大/最小的盒子)
- Box UVA
- 10215 - The Largest/Smallest Box ...
- UVA 12293 Box Game
- uva 501 Black Box
- UVA 501 Black Box
- Uva-10648-Chocolate Box
- UVa 10577 - Bounding box
- uva 12293 Box Game
- uva 1587 - Box
- uva 1587 - Box
- UVa 1587 - Box
- UVa 1587 - Box
- UVa 1587 Box
- Uva-1587-Box-AC
- UVA 10161-Ant on a Chessboard
- UVA 10177 - (234)-D SqrRectsCubesBoxes
- UVA 10182 - Bee Maja
- UVA 10195 - The Knights Of The Round Table
- UVA 10209 - Is This Integration
- UVA 10215 - The LargestSmallest Box ...
- UVA 10310 - Dog and Gopher
- UVA 439 - Knight Moves
- POJ 1979 - Red and Black
- POJ 3126 - Prime Path
- POJ 3278 - Catch That Cow
- POJ 2312 - Battle City
- POJ 2251 - Dungeon Master
- POJ 2225 - Asteroids!