CodeForces - 77E :Martian Food (笛卡尔定理+韦达定理)

E. Martian Food
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Have you ever tasted Martian food? Well, you should.

Their signature dish is served on a completely black plate with the radius of R, flat as a pancake.

First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate as possible staying entirely within the plate. I. e. Golden Honduras touches the edge of the plate from the inside. It is believed that the proximity of the portion of the Golden Honduras to the edge of a plate demonstrates the neatness and exactness of the Martians.

Then a perfectly round portion of Pink Guadeloupe is put on the plate. The Guadeloupe should not overlap with Honduras, should not go beyond the border of the plate, but should have the maximum radius. I. e. Pink Guadeloupe should touch the edge of the plate from the inside, and touch Golden Honduras from the outside. For it is the size of the Rose Guadeloupe that shows the generosity and the hospitality of the Martians.

Further, the first portion (of the same perfectly round shape) of Green Bull Terrier is put on the plate. It should come in contact with Honduras and Guadeloupe, should not go beyond the border of the plate and should have maximum radius.

Each of the following portions of the Green Bull Terrier must necessarily touch the Golden Honduras, the previous portion of the Green Bull Terrier and touch the edge of a plate, but should not go beyond the border.

To determine whether a stranger is worthy to touch the food, the Martians ask him to find the radius of the k-th portion of the Green Bull Terrier knowing the radii of a plate and a portion of the Golden Honduras. And are you worthy?

Input

The first line contains integer t (1 ≤ t ≤ 104) — amount of testcases.

Each of the following t lines contain three positive integers: the radii of the plate and a portion of the Golden Honduras R and r(1 ≤ r < R ≤ 104) and the number k (1 ≤ k ≤ 104).

In the pretests 1 ≤ k ≤ 2.

Output

Print t lines — the radius of the k-th portion of the Green Bull Terrier for each test. The absolute or relative error of the answer should not exceed 10 - 6.

Examples
input
2
4 3 1
4 2 2
output
0.9230769231
0.6666666667
Note

Dish from the first sample looks like this:

CodeForces - 77E :Martian Food (笛卡尔定理+韦达定理)_第1张图片

Dish from the second sample looks like this:

CodeForces - 77E :Martian Food (笛卡尔定理+韦达定理)_第2张图片


(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)

(2)韦达定理  

我们现在k1,k2,k3均为已知,代入上面笛卡尔定理的式子便能求解出k4

易发现这是一个关于k4的二次方程,化简为标准形式为:

                                            k4^2-2(k1+k2+k3)k4+(k1+k2+k3)^2-2*(k1*k1+k2*k2+k3*k3)=0

直接求解是挺困难的,设两个解是x1,x2,利用韦达定理:

                                                                                x1+x2=2(k1+k2+k3)



因为k4所代表的圆与前三个圆均相切,对于此题x1,x2就是k3所代表圆左右两个圆的曲率。

这样我们就可以类似迭代的方式,不断往后递推求解。

#include
using namespace std;
int main()
{
    int T,n;cin>>T;
    double R1,R2,R3;
    while(T--)
    {
        scanf("%lf%lf%d",&R1,&R2,&n);
        R3=R1-R2;
        double k1=-1/R1;
        double k2=1/R2;
        double k3=1/R3;
        double k4=k1+k2+k3;
        double ans;
        for(int i=1;i<=n;i++)
        {
            double R4=1/k4;
            ans=R4;
            double k5=2*(k1+k2+k4)-k3;
            k3=k4;
            k4=k5;
        }
        printf("%0.10lf\n",fabs(ans));
    }
    return 0;
}


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