2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle

原题:

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

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle_第1张图片

Figure 1.

(Left) Inserting a smaller circle C_{1}C1 into a blank area bounded by the circle C_{a}CaC_{b}Cb and C_{c}Cc.

(Right) An enlarged view of inserting a smaller and smaller circle C_{k}Ck into a blank area bounded by C_{a}CaC_{c}Cc and C_{k-1}Ck1 (2 \leq k \leq N2kN), so that the inserted circle C_{k}Ck is always tangent to the three outer circles, C_{a}CaC_{c}Cc, and C_{k-1}Ck1.

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

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

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

1 \leq k \leq N1kN, and 10^{4} \leq R \leq 10^{7}104R107.

Input Format

Contains l + 3l+3 lines.

Line 11ll ----------------- the number of test cases, ll is an integer.

Line 22RR ---------------- RR is a an integer followed by a decimal point,then followed by a digit.

Line 33kk ---------------- test case #11kk is an integer.

\ldots

Line i+2i+2kk ----------------- test case # ii.

\ldots

Line l +2l+2kk ------------ test case #ll.

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

Output Format

Contains ll lines.

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

\ldots

Line iikk R_{k}Rk ----------------output for kk and the value of R_{k}Rk at the test case # ii, each of which should be separated by a blank.

Line llkk R_{k}Rk ----------------output for kk and the value ofR_{k}Rk at the test case # ll, each of which should be separated by a blank.

样例输入

1
152973.6
1
-1

样例输出

1 23665
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int PI = 3.14159;
const double sqrt3 = sqrt(3.0);
int main() {
    int L; scanf("%d", &L);
    double R; scanf("%lf", &R);
    for (int i = 1; i <= L; i++) {
        int K; scanf("%d", &K);
        double r0 = R, y0 = 0;
        for (int j = 1; j <= K; j++) {
            double y = (1.0*(y0+r0-R)*(y0+r0-R) - 4.0*R*R) / (2.0*(y0+r0-R) - 2.0*sqrt3*R);
            double r = y - y0 - r0;
            r0 = r, y0 = y;
        }
        int ans = r0;
        printf("%d %d\n", K, ans);
    }
    int temp; scanf("%d", &temp);
    return 0;
}


你可能感兴趣的:(2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle)