URAL 1874. Football Goal(数学 浮点数三分)

来源:互联网 发布:经济学书籍推荐 知乎 编辑:程序博客网 时间:2024/06/05 16:21

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1874


Unlike most students of the Mathematical Department, Sonya is fond of not only programming but also sports. One fine day she went to play football with her friends. Unfortunately, there was no football field anywhere around. There only was a lonely birch tree in a corner of the yard. Sonya searched the closet at her home, found two sticks, and decided to construct a football goal using the sticks and the tree. Of course, the birch would be one of the side posts of the goal. It only remained to make the other post and the crossbar.
Sonya wanted to score as many goals as possible, so she decided to construct a goal of maximum area. She knew that the standard football goal was rectangular, but, being creative, she assumed that her goal could have the form of an arbitrary quadrangle.
You can assume that the birch tree is a segment of a straight line orthogonal to the ground.

Input

The only line contains integers a and b, which are the lengths of the sticks (1 ≤ ab ≤ 10 000). It is known that the total length of the sticks is less than the height of the birch tree.

Output

Output the maximum area of the goal that can be constructed with the use of the sticks and the birch tree. The answer must be accurate to at least six fractional digits.

Sample

inputoutput
2 2
4.828427125
Problem Author: Fedor Fominykh
Problem Source: Ural Regional School Programming Contest 2011


题意:

形成球门,现在有两根棍子,和一棵树形成的柱子(与地面垂直)!

求能形成的最大面积?(地面也算一边)

PS:


四边形的面积ACBD由三角形ACB和三角形ABD组成。

设AB的长度为z,

那么三角形ACB的最大面积是 z*z/4.

三角形ABD的面积用海伦公式可以表示出来。

z是变长,范围是[0,x+y].

面积公式是凸性函数,对z进行三分就行了。

代码如下:

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>using namespace std;#define eps 1e-8double cal(double a, double b, double c){    double p = (a+b+c)/2;    return sqrt(p*(p-a)*(p-b)*(p-c))+c*c/4.0;}int main(){    double a, b;    while(~scanf("%lf %lf",&a,&b))    {        if(a > b)        {            swap(a, b);        }        double l = 0;        double r = a+b;        while(l + eps < r)        {            double mid = (l+r)/2.0;            double s1 = cal(a, b, mid);            double midmid = (mid+r)/2.0;            double s2 = cal(a, b, midmid);            if(s1 > s2)                r = midmid;            else                l = mid;        }        printf("%.8lf\n",cal(a, b, l));    }    return 0;}


1 0