Sunday, February 27, 2011

375- Inscribed Circles and Isosceles Triangles


#include<iostream>
#include<cstdio>
#include<math.h>
#include<cstdlib>
using namespace std;
int main()
{
    int t;
    long double b,h,a,r,R;
    //freopen("in.txt","r",stdin);
    cin>>t;
    while(t--)
    {
        R=0;
        cin>>b>>h;
        a=sqrt(4*h*h+b*b)/2.0;
        r=b*h/(2*a+b);
        while(r>=0.000001)
        {
            R+=r;
            b*=(h-2*r)/h;
            a*=(h-2*r)/h;
            h=h-2*r;
            r=b*h/(2*a+b);
        }
        if(t)
            printf("%13.6Lf\n\n",8*atan(1)*R);
        else
            printf("%13.6Lf\n",8*atan(1)*R);
    }
    exit(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.