uva 11524-InCircle(二分法)
題意:三角形ABCの内接円はその3辺をそれぞれm 1:n 1,m 2:n 2,m 3:n 3の割合に分ける.また内接円の半径rが知られており、三角形ABCの面積を求める.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#define sqr(a) (a)*(a)
#define eps 1e-12
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
#define pi asin(1.0)
using namespace std;
int sig(double a)
{
return (a>eps)-(a<-eps);
}
int main()
{
int t;
double r,m1,n1,m2,n2,m3,n3,k1,k2,k3;
double left,right,mid,thy,th1,th2,th3;
cin>>t;
while(t--)
{
cin>>r>>m1>>n1>>m2>>n2>>m3>>n3;
k1=sqr(n1);
k2=sqr(n2/m2)*k1;
k3=sqr(m1);
left=min(sqrt(3/k1)*r,sqrt(3/k2)*r);
left=min(left,sqrt(3/k3)*r);
right=max(sqrt(3/k1)*r,sqrt(3/k2)*r);
right=max(right,sqrt(3/k3)*r);
mid=(left+right)/2;
while(sig(right-left)>0)
{
th1=r/sqrt(k1*sqr(mid)+sqr(r));
th2=r/sqrt(k2*sqr(mid)+sqr(r));
th3=r/sqrt(k3*sqr(mid)+sqr(r));
thy=asin(th1)+asin(th2)+asin(th3);
int f=sig(thy-pi);
if(f==0) break;
else if(f<0) right=mid;
else left=mid;
mid=(left+right)/2;
}
thy=2*asin(r/sqrt(k1*sqr(mid)+sqr(r)));
double area=(n1+m1)*mid/2*(n2+m2)*n1/m2*mid*sin(thy);
cout<<fixed<<setprecision(4)<<area<<endl;
}
return 0;
}