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.
OutputFor 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 1Sample Output
3.14159 3.14159
笛卡尔定理
![](https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D135/sign=d038ff39fe03918fd3d139c9643c264b/5ab5c9ea15ce36d366262be933f33a87e850b1cd.jpg)
![](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D213/sign=e8ad96cd29a446237acaa263ab237246/b3119313b07eca80e0b7d550982397dda04483d3.jpg)
![](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D223/sign=f6c953f30bfa513d55aa6bdc0e6d554c/d439b6003af33a878e16c635c55c10385343b5a2.jpg)
![](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D87/sign=b2a00564d8b44aed5d4eb3e3b21cbb88/b17eca8065380cd7a59ba4c3a344ad3459828112.jpg)
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D62/sign=bcd2dd4e372ac65c63056571fbf2ca20/d0c8a786c9177f3ee15cfd2372cf3bc79f3d56b7.jpg)
#include<cstdio> #include<algorithm> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const double eps = 1e-14; const double PI = acos(-1.0); void Debug() { puts(""); cout<<"+++++++++++++++++++++++++++分界线++++++++++++++++++++++++++++++"<<endl; for(int i=0; i<1; i++) { for(int j=0; j<1; j++) { cout<<13221321321312321<<" "; } cout<<endl; } cout<<"+++++++++++++++++++++++++++分界线++++++++++++++++++++++++++++++"<<endl; puts(""); } int n; double r1, r2, r3,r4; double ans; void sovel() { if(r1 < r2) swap(r1,r2); r3 = r1-r2; double k1 = -1.0/r1, k2 = 1.0/r2, k3 = 1.0/r3, k4 = k1+k2+k3; ans = r3*r3; for(int i = 2; i <= n; i++) { r4 = 1.0/k4; ans += r4*r4; if(r4*r4 < eps) break; if(i+1 <= n) ans +=r4*r4, i++; double k5 = 2*(k1+k2+k4) - k3; k3 = k4; k4 = k5; } printf("%.5f\n", ans*PI); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int T; cin >> T; while(T--) { cin >> r1 >>r2 >> n; sovel(); } return 0; }
圆的反演 :
http://www.cnblogs.com/flipped/p/7397942.html