Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.

A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.

Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.

Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.

Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.

Sample Input

2
2 3
0 0
0 0
2 3
0 0
5 0

Sample Output

Case #1: 15.707963
Case #2: 2.250778

Source
2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)


题意:
给定两个圆环的圆心,以及 r ,R ,求圆环相交的面积;


直接求-----------------> 不现实,
** 不妨将图画出来**
将每一部分面积分别表示出来
那么乱搞加加减减,
可以得出
设一个圆环的大圆为A,小圆为a;另一个为B,b;
那么S= S(A∩B)+S(a∩b)-S(a∩B)-S(A∩b);

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 100005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)


inline int rd() {
    int x = 0;
    char c = getchar();
    bool f = false;
    while (!isdigit(c)) {
        if (c == '-') f = true;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return f ? -x : x;
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }


double interS(double x1, double y1, double r1, double x2, double y2, double r2) {
    double dis = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
    if (dis >= (r1 + r2)*(r1 + r2))return 0.0;
    if (dis <= (r1 - r2)*(r1 - r2)) {
        if (r1 < r2)return pi * r1*r1;
        else return pi * r2*r2;
    }
    dis = sqrt(dis*1.0);
    double a1 = acos((r1*r1 + dis * dis - r2 * r2) / (2.0*r1*dis));
    double a2 = acos((r2*r2 + dis * dis - r1 * r1) / (2.0*dis*r2));
    double s1 = a1 * r1*r1;
    double s2 = a2 * r2*r2;
    double tmp = (r1 + r2 + dis) / 2.0;// 海伦公式
    double s3 = 2.0*sqrt(tmp*(tmp - r1)*(tmp - r2)*(tmp - dis));
    return s1 + s2 - s3;
}

int main()
{
    //ios::sync_with_stdio(false);
    int T; rdint(T);
    double r1, r2;
    double X1, X2, Y1, Y2;
    int cnt = 1;
    while (T--) {
        scanf("%lf%lf%lf%lf%lf%lf", &r1, &r2, &X1, &Y1, &X2, &Y2);
        double res = 0;
        res += interS(X1, Y1, r1, X2, Y2, r1);
        res += interS(X1, Y1, r2, X2, Y2, r2);
        res -= interS(X1, Y1, r1, X2, Y2, r2);
        res -= interS(X1, Y1, r2, X2, Y2, r1);
        printf("Case #%d: ", cnt++);
        printf("%.6lf\n", 1.0*res);
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 100005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)


inline int rd() {
    int x = 0;
    char c = getchar();
    bool f = false;
    while (!isdigit(c)) {
        if (c == '-') f = true;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return f ? -x : x;
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }


double interS(double x1, double y1, double r1, double x2, double y2, double r2) {
    double dis = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
    if (dis >= (r1 + r2)*(r1 + r2))return 0.0;
    if (dis <= (r1 - r2)*(r1 - r2)) {
        if (r1 < r2)return pi * r1*r1;
        else return pi * r2*r2;
    }
    dis = sqrt(dis*1.0);
    double a1 = acos((r1*r1 + dis * dis - r2 * r2) / (2.0*r1*dis));
    double a2 = acos((r2*r2 + dis * dis - r1 * r1) / (2.0*dis*r2));
    double s1 = a1 * r1*r1;
    double s2 = a2 * r2*r2;
    double tmp = (r1 + r2 + dis) / 2.0;// 海伦公式
    double s3 = 2.0*sqrt(tmp*(tmp - r1)*(tmp - r2)*(tmp - dis));
    return s1 + s2 - s3;
}

int main()
{
    //ios::sync_with_stdio(false);
    int T; rdint(T);
    double r1, r2;
    double X1, X2, Y1, Y2;
    int cnt = 1;
    while (T--) {
        scanf("%lf%lf%lf%lf%lf%lf", &r1, &r2, &X1, &Y1, &X2, &Y2);
        double res = 0;
        res += interS(X1, Y1, r1, X2, Y2, r1);
        res += interS(X1, Y1, r2, X2, Y2, r2);
        res -= interS(X1, Y1, r1, X2, Y2, r2);
        res -= interS(X1, Y1, r2, X2, Y2, r1);
        printf("Case #%d: ", cnt++);
        printf("%.6lf\n", 1.0*res);
    }
    return 0;
}