【ZOJ】3806 Incircle and Circumcircle

传送门:【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 ;
}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值