刚开始自己做的时候以为每个内切圆的直径连起来刚好等于高,那个精度并没有什么用,显然想当然了,
而是每个内切圆都相当于一个新的三角形,重新求三角形的底边和高,利用最开始的底和高求出tan@和
tan@/2,然后逐层递归即可。
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
#include<memory>
#include<climits>
#include<cstdlib>
using namespace std;
#define LL long long
#define INT (1LL<<62);
const double eps=1e-6;
const double pi=4*atan(1.0);
int dcmp(double x)
{
return fabs(x)<eps?0:(x>0?1:-1);
}
/*struct point
{
double x,y;
point() {};
point(double x,double y):x(x),y(y){};
point operator + (point b)
{
return point(x+b.x,y+b.y);
}
point operator - (point b)
{
return point(x-b.x,y-b.y);
}
point operator / (double b)
{
return point(x/b,y/b);
}
point operator * (double b)
{
return point(x*b,y*b);
}
};
double dot(point a,point b)
{
return a.x*b.x+a.y*b.y;
}
double length(point a)
{
return sqrt(dot(a,a));
}
double dd(point a,point b)
{
return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
point zx(point a)
{
double d=length(a);
return point(-a.y/d,a.x/d);
}*/
int main()
{
int t;
cin>>t;
while(t--)
{
double b,h;
cin>>b>>h;
double r;
double sum=0;
while(1)
{
double l=atan(h/(b/2));
r=tan(l/2)*b/2;
if(r<0.000001) break;
sum=sum+2*pi*r;
b=b*(h-2*r)/h;
h=h-2*r;
}
printf("%13.6f\n",sum);
if(t) cout<<endl;
}
return 0;
}