Area of Circles II(数论)

描述

There are two circles on the plane. Now you must to calculate the area which they cover the plane. For example, in Figure 1, the area of the red region is the answer of this problem.

输入

The input contains multiple test cases. The first line contains an integer T describing the number of test cases. Each case contains two lines. One line describes one circle. For each line has three integers x, y, r, indicating the coordinate of the centre and radius. All the numbers are separated by spaces. All the input integers are within the range of [-1000, 1000].

输出

For each test case, output one line containing a number with 3 digits after decimal point representing the answer describing above.

样例输入

2
2 2 2
1 4 3
2 2 1
-2 -2 1

样例输出

32.462
6.283

 

只能说是高中数学知识,模拟一下就完了。但是我好像把学得还回去了,结果想了好久好久。。。。。。

#include<stdio.h>
#include<math.h>
double min(double a,double b)
{
    if(a>b) a=b;
    return a;
}
double max(double a,double b)
{
    if(a<b) a=b;
    return a;
}
int main()
{
    double x1,x2,y1,y2,r1,r2,S;
    int n;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2);
        double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        double s1=acos(-1)*r1*r1;
        double s2=acos(-1)*r2*r2;
        if(d>=r1+r2) S=s1+s2;
        else if(d<=max(r1,r2)-min(r1,r2)) S=max(s1,s2);
        else
        {
            double A=2*acos((r1*r1+d*d-r2*r2)/(2*r1*d));
            double shan1=A*r1*r1/2;
            double sanjiao1=sin(A)*r1*r1/2;
            double B=2*acos((r2*r2+d*d-r1*r1)/(2*r2*d));
            double shan2=B*r2*r2/2;
            double sanjiao2=sin(B)*r2*r2/2;
            S=s1+s2-(shan1+shan2-sanjiao1-sanjiao2);
        }
        printf("%.3lf\n",S);
    }
}

 

转载于:https://www.cnblogs.com/mayouyou/p/9030693.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值