hdu6158 The Designer
地址: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
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
![](http://acm.split.hdu.edu.cn/data/images/C779-1009-1.png)
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.
![](http://acm.split.hdu.edu.cn/data/images/C779-1009-1.png)
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(1≤t≤1200), 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 (1≤R≤100), 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 (1≤N≤10 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).
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
思路:
圆的反演。
把俩个大圆的切点当做反演中心,可以得到下图:
这样每个圆都变成同大小的圆了,那怎么计算半径呢?
这样一次算下去,直到后面的圆不影响答案时结束。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define MP make_pair 6 #define PB push_back 7 typedef long long LL; 8 typedef pair<int,int> PII; 9 const double eps=1e-8; 10 const double PI=acos(-1.0); 11 const int K=1e6+7; 12 const int mod=1e9+7; 13 14 int main(void) 15 { 16 int t,n;cin>>t; 17 while(t--) 18 { 19 double lx,rx,x,y,d,r,nr,s,ans=0; 20 scanf("%lf%lf%d",&lx,&rx,&n); 21 lx=0.5/lx,rx=0.5/rx; 22 if(lx>rx) swap(lx,rx); 23 x=(lx+rx)/2.0; 24 r=(rx-lx)/2.0; 25 for(int i=1;i<=n;i++) 26 { 27 y=(i/2)*r*2; 28 d=sqrt(x*x+y*y); 29 nr=0.5*(1.0/(d-r)-1.0/(d+r)); 30 s=nr*nr*PI; 31 if(s<1e-12) break; 32 ans+=s; 33 } 34 printf("%.5f\n",ans); 35 } 36 37 return 0; 38 }
作者:weeping
出处:www.cnblogs.com/weeping/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。