light oj 1118 Incredible Molecules

1118 - Incredible Molecules
Time Limit: 0.5 second(s) Memory Limit: 32 MB

In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There are some circular molecules, when two of them collide, they overlap with each other, and it's hard to find that which one is over the other one.

Given two molecules as circles, you have to find the common area of the given molecules that is shaded in the picture.

Overlapping Molecules

Input

Input starts with an integer T (≤ 12), denoting the number of test cases.

Each case contains six integers x1, y1, r1 and x2, y2, r2. Where (x1, y1) is the center of the first molecule and r1 is the radius and (x2, y2) is the center of the second molecule and r2 is the radius. Both the radiuses are positive. No integer will contain more than 3 digits.

Output

For each test case, print the case number and the common area of the given molecules. Errors less than 10-6 will be ignored.

Sample Input

Output for Sample Input

3

0 0 10 15 0 10

-10 -10 5 0 -10 10

100 100 20 100 110 20

Case 1: 45.3311753978

Case 2: 35.07666099

Case 3: 860.84369

 


PROBLEM SETTER: JANE ALAM JAN


題意:計算兩圓相交的面積

首先判斷兩圓的位置是相交,內含還是外離,如果相交再計算對應圓心角角度,用兩個扇形面積減去一個三角形的面積就是答案


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define foRR(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))

const int inf=0x3f3f3f3f;
int t,XX,Xx,YY,Yy,RR,Rr;//定義成x1,x2,y1,y2就CE了,很迷
double ans;

void solve()
{
    double a=sqrt(sqr(XX-Xx)+sqr(YY-Yy));
    if(a+eps>=(RR+Rr))//判斷外離
    {
        ans=0;
        return;
    }
    else if(a<fabs(RR-Rr)+eps)//判斷內含
    {
        double o=min(RR,Rr);
        ans=pi*o*o;
        return ;
    }
    double p1=acos((sqr(RR)+sqr(a)-sqr(Rr))/(2.0*a*RR));//計算兩個扇形圓心角的一半,因爲計算公式會乘0.5,所以不用乘2
    double p2=acos((sqr(Rr)+sqr(a)-sqr(RR))/(2.0*a*Rr));
    ans=p1*sqr(RR)+p2*sqr(Rr)-sin(p1)*a*RR;
}

int main()
{
    sf("%d",&t);
    foRR(i,t)
    {
        sf("%d%d%d%d%d%d",&XX,&YY,&RR,&Xx,&Yy,&Rr);
        solve();
        pf("Case %d: %.6lf\n",i,ans);
    }
    return 0;
}


發佈了73 篇原創文章 · 獲贊 7 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章