HDU 6158 (计算几何+笛卡尔定理+韦达定理)

来源:互联网 发布:做动画的app mac 编辑:程序博客网 时间:2024/04/27 20:46
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 theFigure1



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 theFigure1.

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) likeFigure1.
    
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(1t1200), which means the number of the test cases. For each test case, the first line insist of two integersR1 and R2 separated by a space (1R100), 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 integerN (1N10 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
25 414 51
 

Sample Output
3.141593.14159
 
emmm.........
说实话这个题要怎么讲仔细我也不清楚,
要用到两个定理:
①笛卡尔定理:若平面上四个半径为r1、r2、r3、r4的圆两两相切于不同点(就是有6个不同切点),则其半径满足以下结论:
(k1+k2+k3+k4)2=2(k21+k22+k23+k24)

( K = 1 / R )(如果 K1 与其他圆均外切则为 +K1 ,否则  -K1  ,其他的 K 也是这样)
然这四个K对应的R就分别是题目给的大圆和小圆以及两个相邻的要填进去的小小圆。。。。。。
然后递推,两个相邻的小小圆其中有一个已知然后推出来另外一个
其实是这样推的,令只有K4未知,然后化简式子就得出一个关于K4的一元二次方程,不要直接求出K4
这个K4根据这个方程是有两个解的,然后这两个解就是走有两个圆的大小。
这就用到韦达定理:
②:
设一元二次方程
中,两根x₁、x₂有如下关系:
我们用第一个式子即可
第一个小小圆:2*r1=2*R-2*r(注:题目给的大圆和小圆的圆心不是在一起的)
然后慢慢推吧
N很大的时候的圆很小面积可以无视了


具体怎么操作看代码:

#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <cmath>#include <map>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 10000005#define Mod 10001using namespace std;typedef long long LL;const double eps=1e-13;double R,r;int n;int main(){    int T;    scanf("%d",&T);    while(T--)    {        scanf("%lf%lf%d",&R,&r,&n);        if(R<r)swap(R,r);        double ans=(R-r)*(R-r);        double r1=1.0/R,r2=1.0/r;        double k1=1.0/(R-r),k2=k1+r2-r1;//k2:求第二个小小圆,因为第二个和第三个相等        for(int i=1;i<n;i++)        {            double res=1.0/k2;            ans+=res*res;            if(i+1<n)            {                i++;                ans+=res*res;            }            if(res*res<eps)break;            double k=k2;            k2=2*k2+2*r2-2*r1-k1;            k1=k;        }        ans*=4*atan(1);        printf("%.5f\n",ans);    }    return 0;}

本人蒟蒻,如有错误,还望指正。



原创粉丝点击