您的位置:首页 > 其它

Incircle and Circumcircle - ZOJ 3806 几何

2014-08-24 22:16 78 查看
Incircle and Circumcircle

Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge

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 r and 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!


题意:给你一个小圆半径和大圆半径,然后让你构造一个三角形,使得小圆是这个三角形的内切圆,大圆是这个三角形的外切圆,输出这个三角形的三条边。

思路:首先在这个三角形是正三角形时,内切圆半径最大,所以有解的条件是R>=r*2,然后二分枚举底边的长度0-R*sqrt(3),构造等腰三角形,然后当底边变小时,内切圆的半径也会变小。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{ int i,j,k;
  double di,yao,r,R,ldi,rdi,mi,h,bian,eps=1e-9,O,o;
  while(~scanf("%lf%lf",&r,&R))
  { if(R/r-2<-eps)
    { printf("NO Solution!\n");
      continue;
    }
    ldi=0;
    rdi=R*sqrt(3)/2;
    while(rdi-ldi>eps)
    { mi=(rdi+ldi)/2;
      O=sqrt(R*R-mi*mi);
      h=O+R;
      bian=sqrt(h*h+mi*mi);
      o=(2*mi*h)/(2*bian+mi*2);
      if(o<r)
       ldi=mi;
      else
       rdi=mi;
    }
    mi=(rdi+ldi)/2;
    O=sqrt(R*R-mi*mi);
    h=O+R;
    bian=sqrt(h*h+mi*mi);
    o=(2*mi*h)/(2*bian+mi*2);
    printf("%.18f %.18f %.18f\n",mi*2,bian,bian);
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: