joj 2437: The grabber 等周定理变形 一直两端点和周长,求最大面积

 2437: The grabber


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K26662Standard

When you buy land at the vast grassland, the area depends on your equestrianism. The farmer will give you a horse after received a fixed amount of money. You and your horse set out at sunrise, back home at sunset. The total enclosed region by your path is what you gained. But if you can't back on time, you will get nothing.

If you know how long you can walk, you may know the best way is draw a circle which perimeter is just enough.

Another farmer gives a new method with more money. The buyer should give two point before. And then start from one point, arrive to another. The enclosed region by the straight line between the two points and your path is what you gained.

Do you know the best result when you know the distance that you can move.

Input

On each line, two positive double value d and s are given. d is the distance between the fixed two points, s is the distance that you can drive.

Output

Output the maximal area that you can gain, the result is displayed to a precision of 3 digit after the decimal point.

Sample Input

1 2
2 3.14

Sample Output

0.528
1.570

Hint

Please notice the precision. The error value in standard program is 1e-10.
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double pi=acos(-1.0);
double maxArea(double d,double s)
{
    //二分枚举角度
    double l=0,r=2*pi;
    while(l<r)
    {
        if(fabs(l-r)<1e-10) break;
        double mid=(l+r)/2;//角度
        double radius=(d/2)/sin(mid/2);
        double ts=radius*mid;
        if(ts<s) l=mid;
        else r=mid;
    }
    double ra=s/r;//最终半径
    return s*ra/2;//面积
}
int main()
{
    double d,s;
    while(scanf("%lf%lf",&d,&s)==2)
    {
        printf("%.3lf/n",maxArea(d,s));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值