地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6158
题目:
The Designer
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1381 Accepted Submission(s): 289
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 <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double PI=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int main(void)
{
int t,n;cin>>t;
while(t--)
{
double lx,rx,x,y,d,r,nr,s,ans=;
scanf("%lf%lf%d",&lx,&rx,&n);
lx=0.5/lx,rx=0.5/rx;
if(lx>rx) swap(lx,rx);
x=(lx+rx)/2.0;
r=(rx-lx)/2.0;
for(int i=;i<=n;i++)
{
y=(i/)*r*;
d=sqrt(x*x+y*y);
nr=0.5*(1.0/(d-r)-1.0/(d+r));
s=nr*nr*PI;
if(s<1e-) break;
ans+=s;
}
printf("%.5f\n",ans);
} return ;
}