问题描述:
A triangle is one the basic shapes in geometry. It's a polygon with three vertices and three sides which are line segments. A triangle with vertices A, B, C is denoted ΔABC. And its three sides, BC, CA, AB are often denoted a, b and c.
The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle's incenter and the radius of the incircle is called inradius, which is denoted r.
The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denoted R.
It's very easy to calculate r and R after knowing a, b and c. Now you are given rand R, can you calculate a valid triple (a, b, c)?
Input
There are multiple cases. Each case has two positive integers r and R in one line. (r and R are less than 105)
Ouput
For each case, print three floating numbers a, b and c in one line if it's possible to get r and R. If there are no possible tuples, print "NO Solution!".
The judge program uses your a, b and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.
Sample Input
1 2 2 5 9 9
Sample Ouput
3.464101615137754587 3.464101615137754587 3.464101615137754587 6 8 10 NO Solution!
题目题意:题目给我们一个(三角形的)外接圆和一个内接圆的半径,让我们求出一个三角形满足题意,输出三角形三边长.
题目分析:这道题目,当时是没有什么思路的,过后看到这个大佬的博客,才理解了,写出了自己的AC代码.
大佬的链接(讲的很好):点击打开链接
大佬里面讲的很清楚了,我的代码只是在二分时,用了自己的判断方法。
我的思路是通过知道底边mid,然后勾股定理求腰a,求高,我们算出此时这个三角形的面积s
根据等面积法,我们可以得到等式p*r1=s (其中p为三角形的周长的一半),求出每个三角形的内接圆的半径r1,然后和题目的内接圆的半径相比较,来更新范围.
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double epx=1e-10;
double spow(double a)
{
return a*a;
}
int main()
{
double R,r;
while (scanf("%lf%lf",&r,&R)!=EOF) {
if (R<2*r) {
printf("NO Solution!\n");
continue;
}
double left=0,right=sqrt(3.0)*R;
while (right-left>epx) {
double mid=(right+left)/2.0;
double a=sqrt(spow(sqrt(spow(R)-spow(mid/2.0))+R)+spow(mid/2.0));
double s=(sqrt(spow(R)-spow(mid/2.0))+R)*mid/2.0;
double p=(a+a+mid)/2.0;
double r1=s/p;
if (r1-r>epx) right=mid;
else left=mid;
}
double a=sqrt(spow(sqrt(spow(R)-spow(left/2.0))+R)+spow(left/2.0));
double b=left;
printf("%.16lf %.16lf %.16lf\n",a,a,b);
}
return 0;
}