HDU 1798 Tell me the area .

27 篇文章 0 订阅
12 篇文章 0 订阅

Tell me the area

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 900    Accepted Submission(s): 284

Problem Description
    There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.

 

 

Input
There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.
 

 

Output
For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.
 

 

Sample Input
 
 
0 0 2 2 2 1
 

 

Sample Output
 
 
0.108
 

 

Author
wangye
 

 

Source
 

 

Recommend
wangye
 
几何题,分三种情况讨论…………
假设圆A半径r1 < 圆B半径r2
 
d0 = 圆心距
d1 = A圆心到交线距离
d2 = B圆心到交线距离
arc1 = A圆优弧弓型面积
arc2 = B圆优弧弓型面积
 
情况一:
 
d0 >= r1 + r2
 
两圆相离或外切,area = 0.0
 
情况二:
 
d0 + r1 <= r2 
 
两圆内含或内切,area = A圆面积
 
情况三:
 
r2 - r1 < d0 < r1 + r2
 
相交有两小类:
 
1、d0 >= d1, area = arc1 + arc2
 
2、d0 < d1, area = arc1 + A圆面积 - arc2
 
下面贴上代码:
42905042011-07-29 21:40:46Accepted179862MS208K1115 BC++10SGetEternal{(。)(。)}!
#include <iostream>
#include <cmath>
using namespace std;
#define fp(x) ((x) * (x))
#define fmin(x, y) ((x) < (y)? (x): (y))

int main()
{
    double x1, y1, r1, x2, y2, r2;
    double A, B, C, d, d0, d1, d2, ang1, ang2, taa1, taa2, ara1, ara2, area;

    while (scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &r1, &x2, &y2, &r2) != EOF)
    {
        if (r1 > r2)    //保证圆A半径小于圆B
        {
            swap(r1, r2);
            swap(x1, x2);
            swap(y1, y2);
        }
        A = 2 * (x2 - x1);
        B = 2 * (y2 - y1);
        C = fp(x1) - fp(x2) + fp(y1) - fp(y2) + fp(r2) - fp(r1);
        d = sqrt(fp(A) + fp(B));
        d0 = sqrt(fp(x1 - x2) + fp(y1 - y2));
        d1 = abs(A * x1 + B * y1 + C) / d;
        d2 = abs(A * x2 + B * y2 + C) / d;
        if (d0 >= r1 + r2) area = 0.0;
        else if (d0 + r1 <= r2) area = acos(-1.0) * fp(r1);
        else 
        {
            ang1 = acos(d1 / r1);
            ang2 = acos(d2 / r2);
            taa1 = r1 * d1 * sin(ang1);
            taa2 = r2 * d2 * sin(ang2);
            ara1 = ang1 * fp(r1);
            ara2 = ang2 * fp(r2);
            area = ara2 - taa2;
            if (d0 >= d2)
                area += ara1 - taa1;
            else
                area += acos(-1.0) * fp(r1) - ara1 + taa1;; 
        }
        printf("%.3lf\n", area);
    }

    return 0;
}

 注意DB错误……a - (c + d) = a - c + d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值