Ural-1084. Goat in the Garden(计算几何)

来源:互联网 发布:编辑书的软件 编辑:程序博客网 时间:2024/05/17 06:06

1084. Goat in the Garden

Time limit: 1.0 secondMemory limit: 64 MB
Someone has let a goat in a square kitchen-garden and had bound it to a stake. The stake is driven into the ground in the very midst of the square. The goat is hungry as a hunter and very voracious, and eats everything that can be reached without leaving the square and tearing off the rope. What area of the kitchen-garden will be ate round?

Input

contains lengths of the garden sides and a cord length in meters (positive integers not exceeding 100, located in one line and separated with a space).

Output

should contain an area of the kitchen-garden (in square meters to within 3 symbols after a decimal point), ate round by the goat.

Sample

inputoutput
10 6
95.091


题意:将一只羊拴在长为h的正方形的正中心,绳子长为r,羊能吃到草的面积
思路:当r<h/2时 area=PI*r*r;
 当r>h/2*sqrt(2) area = h*h;
 其他情况:area=(PI-4*acos(h/(2.0*r)))*r*r+2*sqrt(r*r-h*h/4.0)*h
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>using namespace std;const double PI = acos(-1);int main(){//    freopen("in.txt","r",stdin);//    freopen("out.txt","w",stdout);    double h,r;    scanf("%lf%lf",&h,&r);    if(r>=h/2.0*sqrt(2.0))    {        printf("%.3lf\n",h*h);    }    else if(r<=h/2.0)    {        printf("%.3lf\n",PI*r*r);    }    else    {        printf("%.3lf\n",(PI-4*acos(h/(2.0*r)))*r*r+2*sqrt(r*r-h*h/4.0)*h);    }    return 0;}


原创粉丝点击