The Designer
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 761 Accepted Submission(s): 142
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.
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).
5 4
1
4 5
1
3.14159
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define mod 1000000007
typedef long long ll;
int t;
int r1,r2,n;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&r1,&r2,&n);
if(r1<r2) swap(r1,r2);
double k1,k2,k3,k4,ans;
k1=-1.0/r1;
k2=1.0/r2;
k3=1.0/(r1-r2);
k4=k1+k2+k3;
ans=(r1-r2)*(r1-r2);
n--;
for(int i=; i<=n; i+=)
{
double r4=1.0/k4;
if(r4*r4<1e-)
break;
ans+=r4*r4;
if(i+<=n) ans+=r4*r4;
double k5=*(k1+k2+k4)-k3;
k3=k4;
k4=k5;
}
printf("%.5f\n",ans*acos(-1.0));
}
return ;
}