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

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
  
  
2 5 4 1 4 5 1
 

Sample Output
  
  
3.14159 3.14159
 

Source
 
题意:给出两个圆的半径,一大一小,小圆内切于大圆,在大圆内的缝隙间能放若干个小圆(如图)。给出两个半径,和一个数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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值