HDU 6158 The Designer(笛卡尔定理+韦达定理)

22 篇文章 0 订阅
5 篇文章 0 订阅

Problem Description

Nowadays, little haha got a problem from his teacher.His teacher wants to design a big logo for the campus with some circles tangent with each other. And now, here comes the problem. The teacher want to draw the logo on a big plane. You could see the example of the graph in the Figure1
这里写图片描述

At first, haha’s teacher gives him two big circles, which are tangent with each other. And, then, he wants to add more small circles in the area where is outside of the small circle, but on the other hand, inside the bigger one (you may understand this easily if you look carefully at the Figure1.

Each small circles are added by the following principles.
* you should add the small circles in the order like Figure1.
* every time you add a small circle, you should make sure that it is tangented with the other circles (2 or 3 circles) like Figure1.

The teacher wants to know the total amount of pigment he would use when he creates his master piece.haha doesn’t know how to answer the question, so he comes to you.

Task
The teacher would give you the number of small circles he want to add in the figure. You are supposed to write a program to calculate the total area of all the small circles.

Input

The first line contains a integer t(1≤t≤1200), which means the number of the test cases. For each test case, the first line insist of two integers R1 and R2 separated by a space (1≤R≤100), which are the radius of the two big circles. You could assume that the two circles are internally tangented. The second line have a simple integer N (1≤N≤10 000 000), which is the number of small circles the teacher want to add.

Output

For each test case:
Contains a number in a single line, which shows the total area of the small circles. You should out put your answer with exactly 5 digits after the decimal point (NO SPJ).

Sample Input

2
5 4
1
4 5
1

Sample Output

3.14159
3.14159

Source

2017中国大学生程序设计竞赛 - 网络选拔赛

题目大意

有两个圆相内切,在两个圆之间添加n个圆使得其与相邻的圆都相切,添加的顺序如图,求n个圆的总面积。

解题思路

笛卡尔定理+韦达定理

笛卡尔定理

定义:

若平面上四个半径为 r1r2r3r4 的圆两两相切于不同点,则其半径满足以下结论:
(1)若四圆两两外切,则 (4i=11ri)2=24i=11ri2
(2)若半径为 r1r2r3r4 的圆中,则 (1r1+1r2+1r31r4)2=24i=11ri2
                                                                                                                                                   ——百度百科

韦达定理

定义:

设一元二次方程 ax2+bx+c=0(a,b,cR,a0) 中,两根x₁、x₂有如下关系:

x1+x2=ba

x1x2=ca

                                                                                                                                                   ——百度百科

在该题中我们已知四个相切圆中三个的半径,即 r1,r2,r1r2 ,因为圆的曲率 k=1r ,那么我们根据题意可以将笛卡尔定理转化为 (k1+k2+k3+k4)2=2(k21+k22+k23+k24)k1=1r1k2=1r2k3=1r3k4r4
化简可得:
k242(k1+k2+k3)k4(k1+k+2+k3)2+2(k21+k22+k23)=0
根据韦达定理,可得 x1+x2=2(k1+k2+k3)
这里写图片描述

如图所示,当另外一个圆标号为1时,x1+x2即为2和3圆的曲率之和,则2和3的曲率为 (k1+k2+k3) ,当另外一个圆标号为2时,求得的是标号为1和4圆的曲率之和,而标号为1的圆的斜率我们已经求出,便可得4号圆的斜率,如此迭代求解即可。
PS:如果只用n做循环限定条件会超时,当圆的半径小于一定值便可退出,半径限定最大的数量级为1e-7。

代码实现

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdlib.h>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-7
int main()
{
    int T,n;
    double r1,r2;
    double k1,k2,k3,k4,k5;
    double ans;
    scanf("%d",&T);
    while(T--)
    {
        ans=0.0;
        scanf("%lf %lf %d",&r1,&r2,&n);
        if(r1<r2) swap(r1,r2);
        k1=-1.0/r1,k2=1.0/r2,k3=1.0/(r1-r2);
        ans+=(r1-r2)*(r1-r2);
        k4=k1+k2+k3;
        for(int i=1;i<n;i++)
        {
            ans+=(1.0/k4)*(1.0/k4);
            if(1.0/k4<eps) break;
            if(i+1<n) ans+=(1.0/k4)*(1.0/k4),i++;
            k5=2*(k1+k2+k4)-k3;
            k3=k4;
            k4=k5;
        }
        printf("%.5lf\n",ans*PI);
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值