HDU 6158 The Designer 笛卡尔定理+韦达定理 2017ccpc网络赛

来源:互联网 发布:linux添加中文输入法 编辑:程序博客网 时间:2024/06/10 03:03

The Designer

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1198    Accepted Submission(s): 233


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(1t1200), 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 (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 integer N (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
 

Source
2017中国大学生程序设计竞赛 - 网络选拔赛
 
题意:给出两个圆的半径,一大一小,小圆内切于大圆,在大圆内的缝隙间能放若干个小圆(如图)。给出两个半径,和一个数n,问n个小圆的和面积和,小圆编号如图。

思路:笛卡尔定理https://baike.baidu.com/item/%E7%AC%9B%E5%8D%A1%E5%B0%94%E5%AE%9A%E7%90%86/20406483?fr=aladdin

先用笛卡尔定理列出方程求出面积,再用韦达定理递推。因为当n很大的时候,圆的面积就会无限小,答案要求保留5位小数,所以当推到一定次数就可以跳出了。

#include<iostreaM>#include<stdio.h>#include<math.h>#include<algorithm>#define PI acos(-1.0)using namespace std;int main(){    double r3,r4;    int n,m;    scanf("%d",&n);    while(n--)    {        scanf("%lf%lf",&r3,&r4);        if(r3>r4)         swap(r3,r4);         scanf("%d",&m);        double r1,r2;        r2=r4-r3;        double A=(1.0/r2+1.0/r3-1.0/r4);        r1=1.0/A;        //printf("%.5lf\n",r1);        double sum=PI*r2*r2;        double ans=0;        for(int i=1;i<m;i+=2)        {            if(r1*r1<1e-15)                break;            if(i==m-1)            {                ans+=PI*r1*r1;            }            else            {                ans+=2*PI*r1*r1;                //printf("%.5lf\n",ans);                double t=1.0/r2;                r2=r1;                A=(1.0/r2+1.0/r3-1.0/r4);                r1=1.0/(2.0*A-t);                //printf("%.5lf\n",r1);            }        }        printf("%.5lf\n",ans+sum);    }}

阅读全文
0 0
原创粉丝点击