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

畫船聽雨發表於2014-08-25

題目大意:給你一個三角形的內接圓的半徑和外接圓的半徑,讓你找出符合條件的三角形的三條邊的邊長。如果沒有輸出“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;
}


相關文章