hdu 6158 The Designer 计算几何之圆反演 2017中国大学生程序设计竞赛 - 网络选拔赛

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.
 

Input
The first line contains a integer t(1t1200) , 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 ( 1R100 ), 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 ( 1N10 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).
 

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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值