light oj 1118 Incredible Molecules

本文介绍了一个生物实验室场景下的计算问题,即当两个圆形分子发生碰撞时如何计算它们重叠部分的面积。通过输入两个分子的坐标及半径,利用几何原理进行计算并输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值