2017 ACM-ICPC 亚洲区(南宁赛区)网络赛: G. Finding the Radius for an Inserted Circle(笛卡尔定理)

Three circles CaCb, and Cc, all with radius R and tangent to each other, are located in two-dimensional space as shown in Figure 1. A smaller circle C1 with radius R1 (R1<R) is then inserted into the blank area bounded by CaCb, and Cc so that C1 is tangent to the three outer circles, CaCb, and Cc. Now, we keep inserting a number of smaller and smaller circles Ck (2kN) with the corresponding radius Rk into the blank area bounded by CaCc and Ck1 (2kN), so that every time when the insertion occurs, the inserted circle Ck is always tangent to the three outer circles CaCc and Ck1, as shown in Figure 1

Figure 1.

(Left) Inserting a smaller circle C1 into a blank area bounded by the circle CaCb and Cc.

(Right) An enlarged view of inserting a smaller and smaller circle Ck into a blank area bounded by CaCc and Ck1 (2kN), so that the inserted circle Ck is always tangent to the three outer circles, CaCc, and Ck1.

Now, given the parameters R and k, please write a program to calculate the value of Rk, i.e., the radius of the k-th inserted circle. Please note that since the value of Rk may not be an integer, you only need to report the integer part of Rk. For example, if you find that Rk = 1259.89981259.8998 for some k, then the answer you should report is 12591259.

Another example, if Rk = 39.102939.1029 for some k, then the answer you should report is 3939.

Assume that the total number of the inserted circles is no more than 10, i.e., N10. Furthermore, you may assume π=3.14159. The range of each parameter is as below:

1kN, and 104R107.

Input Format

Contains l + 3 lines.

Line 1l ----------------- the number of test cases, l is an integer.

Line 2R ---------------- R is a an integer followed by a decimal point,then followed by a digit.

Line 3k ---------------- test case #1k is an integer.

Line i+2k ----------------- test case # i.

Line l +2k ------------ test case #l.

Line l + 3-1 ---------- a constant -1 representing the end of the input file.

Output Format

Contains lllines.

Line 1k Rk ----------------output for the value of k and Rk at the test case #1, each of which should be separated by a blank.

Line ik Rk ----------------output for k and the value of Rk at the test case # i, each of which should be separated by a blank.

Line lk Rk ----------------output for k and the value ofRk at the test case # l, each of which should be separated by a blank.

样例输入
1
152973.6
1
-1
样例输出
1 23665
思路:

(1)笛卡尔定理

定义一个圆的曲率k=+1/r或-1/r,其中r是其半径。 

若平面有两两相切,且有6个独立切点的四个圆,设其曲率为k1,k2,k3,k4(若该圆与其他圆均外切,则曲率取正,否则取负)则其满足性质: 

                                         (k1+k2+k3+k4)*(k1+k2+k3+k4)=2*(k1*k1+k2*k2+k3*k3+k4*k4)

根据这个定理,我们就可以类似迭代的方式,不断往后递推求解。

#include
using namespace std;
const double PI=3.14159;
int main()
{
    int T,n;
    double R;
    while(scanf("%d",&T)!=EOF&&T!=-1)
    {
        scanf("%lf",&R);
        while(T--)
        {
            scanf("%d",&n);
            double k1=1/R,k2=1/R,k3=1/R;
            double ans;
            for(int i=0;i



你可能感兴趣的:(计算几何,ACM)