原题:
Three circles Ca, Cb, and Cc, all with radius Rand tangent to each other, are located in two-dimensional space as shown in Figure 1. A smaller circle C1 with radius R1 (Ca, Cb, and Cc so that C1 is tangent to the three outer circles, Ca, Cb, and Cc. Now, we keep inserting a number of smaller and smaller circles Ck (2≤k≤N) with the corresponding radius Rk into the blank area bounded by Ca, Cc and Ck−1 (2≤k≤N), so that every time when the insertion occurs, the inserted circle Ck is always tangent to the three outer circles Ca, Cc and Ck−1, as shown in Figure 1 ) is then inserted into the blank area bounded by
Figure 1.
(Left) Inserting a smaller circle C1 into a blank area bounded by the circle Ca, Cb and Cc.
(Right) An enlarged view of inserting a smaller and smaller circle Ck into a blank area bounded by Ca, Cc and Ck−1 (2≤k≤N), so that the inserted circle Ck is always tangent to the three outer circles, Ca, Cc, and Ck−1.
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.8998 for some k, then the answer you should report is 1259.
Another example, if Rk = 39.1029 for some k, then the answer you should report is 39.
Assume that the total number of the inserted circles is no more than 10, i.e., N≤10. Furthermore, you may assume π=3.14159. The range of each parameter is as below:
1≤k≤N, and 104≤R≤107.
Contains l+3 lines.
Line 1: l ----------------- the number of test cases, l is an integer.
Line 2: R ---------------- R is a an integer followed by a decimal point,then followed by a digit.
Line 3: k ---------------- test case #1, k is an integer.
…
Line i+2: k ----------------- test case # i.
…
Line l+2: k ------------ test case #l.
Line l+3: −1 ---------- a constant −1representing the end of the input file.
Contains l lines.
Line 1: k Rk ----------------output for the value of k and Rk at the test case #1, each of which should be separated by a blank.
…
Line i: k Rk ----------------output for k and the value of Rk at the test case # i, each of which should be separated by a blank.
Line l: k 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
#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;
}