light oj 1118

基础(两圆相交面积)
Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

3

0 0 10 15 0 10

-10 -10 5 0 -10 10

100 100 20 100 110 20

Sample Output

Case 1: 45.3311753978

Case 2: 35.07666099

Case 3: 860.84369


有时候用double 处理精度时很容易出错,可以直接用表达式表示


#include <iostream>

#include <cstdio>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-7;
struct node
{
    double x, y, r;
}p[4];


int main()
{
    int t, ncase=1;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%lf %lf %lf %lf %lf %lf",&p[1].x, &p[1].y, &p[1].r, &p[2].x,&p[2].y,&p[2].r);
        if(p[1].r>p[2].r)
        {
            node tmp;
            tmp=p[1], p[1]=p[2], p[2]=tmp;
        }
        double dist=sqrt((p[1].x-p[2].x)*(p[1].x-p[2].x)+(p[1].y-p[2].y)*(p[1].y-p[2].y));
        double s=p[1].r+p[2].r;
        if(dist>=s)
        {
            printf("Case %d: 0\n",ncase++);
        }
        else if(p[2].r>=dist+p[1].r)
        {
            printf("Case %d: %.10f\n",ncase++,pi*p[1].r*p[1].r);
        }
        else
        {
            double x=(p[1].r*p[1].r+dist*dist-p[2].r*p[2].r)/(2*p[1].r*dist);
            double y=(p[2].r*p[2].r+dist*dist-p[1].r*p[1].r)/(2*p[2].r*dist);
            double s=0.5*(p[1].r*dist)*sqrt(1-x*x);
            double s1=(acos(x)/2)*(p[1].r*p[1].r);
            double s2=(acos(y)/2)*(p[2].r*p[2].r);
            double s3=(s1+s2-s)*2;
            printf("Case %d: %.10f\n",ncase++,s3);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值