传送门:【ZOJ】3806 Incircle and Circumcircle
题目分析:
给定内切圆半径r,以及外切圆半径,求满足条件的三角形的三边边长。
当r*2>R时无解,否则一定能找到一个等腰三角形使得正好内切半径为r的圆以及外切半径weiR的圆。最后可以二分等腰三角形的底边,由于已知底边可以直接算出整个三角形的三边边长,如果三角形应该包含的内切圆的半径,大于实际给的r,那么调整二分上界,否则调整二分下界。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std ;
#define REP( i , a , b ) for ( int i = a ; i < b ; ++ i )
#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REV( i , a , b ) for ( int i = a ; i >= b ; -- i )
#define CLR( a , x ) memset ( a , x , sizeof a )
#define CPY( a , x ) memcpy ( a , x , sizeof a )
const double eps = 1e-10 ;
int sgn ( double x ) {
return ( x > eps ) - ( x < -eps ) ;
}
int main () {
double r , R ;
while ( ~scanf ( "%lf%lf" , &r , &R ) ) {
if ( sgn ( R - 2 * r ) < 0 ) printf ( "NO Solution!\n" ) ;
else {
double low = 0 , high = sqrt ( 3.0 ) * R ;
int cnt = 0 ;
while ( high - low > eps ) {
++ cnt ;
double c = ( low + high ) / 2 ;
double a = sqrt ( pow ( sqrt ( R * R - c * c / 4 ) + R , 2 ) + c * c / 4 ) ;
if ( sgn ( pow ( ( sqrt ( r * r + pow ( a - c / 2 , 2 ) ) + r ) , 2 ) + c * c / 4 - a * a ) < 0 ) high = c ;
else low = c ;
//printf ( "%d : a = %.8f , c = %.8f\n" , cnt , a , c ) ;
}
double c = low ;
double a = sqrt ( pow ( sqrt ( R * R - c * c / 4 ) + R , 2 ) + c * c / 4 ) ;
printf ( "%.15f %.15f %.15f\n" , a , a , c ) ;
}
}
return 0 ;
}