U E D R , A S I H C RSS

The Largest Smallest Box/문보창

소감

2006-02-11 Accepted 0.117 448

코드

// 10215 - TheLagestSmallestBox
#include <iostream>
using namespace std;
#include <cmath>
#include <cstdio>

//#include <fstream>
//fstream fin("in.txt");

#define MIN(x,y) (((x) > (y)) ? (y) : (x))

static double L, W;

inline double func(double x)
{
	return 4 * pow(x,3)	- 2 * (L + W) * x * x + L * W * x;
}

void process()
{
	double x1 = (2 * (L + W) + sqrt(pow(2 * (L + W),2) - 12 * L * W)) / 12.0;
	double x2 = (2 * (L + W) - sqrt(pow(2 * (L + W),2) - 12 * L * W)) / 12.0;
	double max = (func(x1) < func(x2)) ? x2 : x1;
	double minValue = MIN(L,W) / 2.0;
	printf("%.3f %.3f %.3f\n", max, 0.0, minValue);
}

int main()
{
	while (cin >> L >> W)
		process();
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2014-01-13 08:25:05
Processing time 0.0124 sec