The Designer
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 830 Accepted Submission(s): 158
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
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.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
题意:
看图,求两个大圆中间夹的小圆的面积和
题解:
圆反演
先介绍圆反演
来自一个 传送门
以及两条有用的定理
反演去之,显然可得(图片来自 大神)
发现不规则的圆可以得到相应数量一样的圆
此时我们反演回去就自然很好就面积了
上图的半径很好求,现在问题是怎么将次圆半径转化为原图中的不规则大小的圆的半径
下面图片来自大牛
消去OC1得到我们需要的r1
即 r1=r2/(OC2^2 - r2^2) * r^2
很简单,大家可以草稿纸上推导一下
然后就是写代码了
但是需要注意一下的就是精度问题
以及当一个圆的面积无法对精度内的答案造成贡献的时候,就应该停止计算,否则会超时
然后发现下面的代码速度蛮快的吗,目前排名第八
#include<math.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
const double eps=1e-12;
const double PI=3.141592653589793238462;
int main()
{
int n,T;
double r1,r2;
// freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf",&r1,&r2);
scanf("%d",&n);
if(r1<r2) swap(r1,r2);
double R=100;
r1=r1*2 , r2=r2*2;
r1=R/r1 , r2=R/r2;
double k=(r2-r1)/2;
n--;
double ans=0,h,d=r1+k,x;
x=R*k/((r1+k)*(r1+k)-k*k);
ans=x*x*PI;
for(int i=1;i<=n/2;i++){
h=2*i*k;
x=R*k/(d*d+h*h-k*k);
x=x*x*PI;
if(x<=eps)
break;
ans+=x*2;
}
if(n%2){
h=2*(n/2+1)*k;
x=R*k/(d*d+h*h-k*k);
x=x*x*PI;
ans+=x;
}
printf("%0.5lf\n",ans);
}
return 0;
}