FZU 2099 魔法阵

手算。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

double pi=acos(-1.0);
double L,R;

int main()
{
    int T; scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf",&L,&R);
        double u=L/sqrt(3.0);
        double ans;
        if(u<=R) 
        {
            ans=pi*R*R;
        }
        else if(R<=1.0/3*L)
        {
            ans=sqrt(3.0)*L*L/3;
        }
        else
        {
                double x=(2*L-sqrt(-4.0/3*L*L+16*R*R))/8;
                double s1=sqrt(3.0)*x*x;

                double h=sqrt(R*R-x*x);
                double s2=x*h;
            
                double alpha=2*asin(x/R);
                double shan=alpha*R*R/2;

                double xiao=s1+s2-shan;

                ans=pi*R*R+6*xiao;
        }
        printf("%.2lf\n",ans);
    }
    return 0;
}

 

posted @ 2016-03-16 07:30  Fighting_Heart  阅读(200)  评论(0编辑  收藏  举报