這道題10.03%的提交通過率真不是蓋的……自己也忽忽悠悠的錯了n次……
這道題乍一看挺簡單了,剛開始自己先求出極大值和極小值,然後比較,但老是不對。後來發現最小值在0和min(l/2, w/2)出取得,而不是0和極小值處=_=
但這樣還是不對,在四捨五入的時候要加一個eps偏移量。。。。
這樣就可以過了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const double eps = 1e-12;
double w, l;
double sq, root1, root2, a, b;
int sig(double x)
{
return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1);
}
double fun(double x)
{
return x * (l - 2 * x) * (w - 2 * x);
}
int main()
{
//freopen("input.txt", "r", stdin);
double v1, v2, r;
while(scanf("%lf %lf", &l, &w) == 2){
a = l + w;
b = l * w;
sq = 4.0 * sqrt(l * l + w * w - l * w);
root1 = (4 * a - sq) / 24.0;
r = root2 = min(w / 2.0, l / 2.0);
v1 = fun(root1);
v2 = fun(root2);
if(sig(root1 - root2) < 0){
if(sig(v1 - v2) == 0){
printf("%.3lf %.3lf", root1, root2);
}else if(sig(v1 - v2) > 0)
printf("%.3lf", root1 + eps);
else printf("%.3lf", root2 + eps);
}else printf("%.3lf", root2 + eps);
root1 = 0;
root2 = r;
printf(" %.3lf %.3lf\n", root1 + eps, root2 + eps);
}
return 0;
}