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
At first,
Each small circles are added by the following principles.
* you should add the small circles in the order like
* every time you add a small circle, you should make sure that it is tangented with the other circles (2 or 3 circles) like
The teacher wants to know the total amount of pigment he would use when he creates his master piece.
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
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个小圆的和面积和,小圆编号如图。
思路:笛卡尔定理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);
}
}