首页 > 代码库 > ZOJ 3806 Incircle and Circumcircle(几何+二分)

ZOJ 3806 Incircle and Circumcircle(几何+二分)

题目大意:给你一个三角形的内接圆的半径和外接圆的半径,让你找出符合条件的三角形的三条边的边长。如果没有输出“NO Solution!”。

首先是判断是否可以构成三角形:

如图:


当 内切圆与外接圆的圆心相同时,为构成符合条件的三角形的最大条件。

这样就找到了关系r*2 == R,所以当r*2 > R时是不存在这样的三角形的。

在满足的条件下,我们通过构造等腰三角形来找到满足条件的三条边,如图:


这道题目的解法是:二分底边长度找到满足条件的长度。

通过二分底边我们可以得到BC的长度,然后在ΔABC中求出AC的长度,AB=R。然后可以得到FC的长度,在ΔFBC中可以求出FB的长度。得到t。

我们在ΔFDE中求出FE,然后得到FC,再在ΔFBC中求出FB的长度tt,比较两次求得的长度,如果tt > t说明有界大了,否则说明左界大了。

注意eps


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 AB, C is denoted ΔABC. And its three sides,BCCAAB are often denoted ab 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 denotedR.

It‘s very easy to calculate r and R after knowing ab and c. Now you are given r and R, can you calculate a valid triple (abc)?

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 ab 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 ab 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!
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)

using namespace std;

const int maxn = 1010;

int main()
{
    double R, r;
    while(cin >>r>>R)
    {
        if(2*r > R)
        {
            cout<<"NO Solution!"<<endl;
            continue;
        }
        double left = 0;
        double right = sqrt(3)*R;
        while(right-left > eps)
        {
            double mid = (left+right)/2.0;
            double t = sqrt(pow(sqrt((pow(R, 2.0)-pow((mid/2.0), 2.0)))+R, 2.0) + pow((mid/2.0), 2.0));
            double tt = pow((sqrt(pow(r, 2.0)+pow((t-mid/2.0), 2))+r), 2.0)+pow((mid/2.0), 2.0);
            if(tt-pow(t, 2.0) < eps) right = mid;
            else left = mid;
        }
        double a = sqrt(pow(sqrt(pow(R, 2.0)-pow(left/2.0, 2.0))+R, 2.0)+pow(left/2.0, 2.0));
        printf("%.18lf %.18lf %.18f\n", a, a, left);
    }
    return 0;
}


ZOJ 3806 Incircle and Circumcircle(几何+二分)