【题意】给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少?

【解题方法】圆环由一个大圆里面套一个小圆,中间部分就是圆环,两圆环相交面积 = 大圆相交的面积 - 2*大圆与小圆相交的面积 + 小圆与小圆相交的面积。

【AC 代码】

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double PI=acos(-1);
#define ll long long
int sq(int x){
    return x*x;
}
double circlejiao(int x1,int y1,int r1,int x2,int y2,int r2)
{
    double ret = 0;
    int dis = sq(x1 - x2) + sq(y1 - y2);
    if(dis >= sq(r1 + r2)) return 0;
    if(dis <= sq(abs(r1 - r2))) return PI * sq(min(r1, r2));
    double alpha = 2 * acosl((sq(r1) + dis - sq(r2)) / 2.0 / r1 / sqrt(dis));
    double beta = 2 * acosl((sq(r2) + dis - sq(r1)) / 2.0 / r2 / sqrt(dis));
    ret += 0.5 * (alpha * sq(r1) + beta * sq(r2));
    ret -= 0.5 * (sinl(alpha) * sq(r1) + sinl(beta) * sq(r2));
    return ret;
}

int main()
{
    int T;
    int x1,y1,r1;
    int x2,y2,r2;
    scanf("%d",&T);
    int cas=1;
    while(T--)
    {
        scanf("%d%d",&r1,&r2);
        scanf("%d%d",&x1,&y1);
        scanf("%d%d",&x2,&y2);
        double s1=circlejiao(x1,y1,r2,x2,y2,r2);
        double s2=circlejiao(x1,y1,r1,x2,y2,r2);
        double s3=circlejiao(x1,y1,r1,x2,y2,r1);
        double ans=s1-2*s2+s3;
        printf("Case #%d: %.6f\n",cas++,ans);
    }
}