码迷,mamicode.com
首页 > 其他好文 > 详细

LightOj1118 - Incredible Molecules(两圆的交集面积)

时间:2016-08-13 15:33:59      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://lightoj.com/volume_showproblem.php?problem=1118

给你两个圆的半径和圆心,求交集的面积;

技术分享

就是简单数学题,但是要注意acos得到的都是小于180度的角,所以这里要注意一下,不要求整个角,求一半的大小;这点让我错的惨不忍睹;

技术分享
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define met(a, b) memset(a, b, sizeof(a))
#define N 1053
#define INF 0x3f3f3f3f
#define PI 4*atan(1)
const int MOD = 10000007;

typedef long long LL;

int main()
{
    int T, t = 1;
    scanf("%d", &T);
    while(T--)
    {
        double r1, r2, x1, x2, y1, y2;
        
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2);
        
        double d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
        
        if( d >= r1+r2 )///相离或相切
        {
            printf("Case %d: %.6f\n", t++, 0.0);
            continue;
        }
        if(d <= fabs(r1-r2))///内含;
        {
            printf("Case %d: %.6f\n", t++, PI*min(r1, r2)*min(r1, r2));
            continue;
        }

        double a = acos((r1*r1+r2*r2-d*d)/(2*r1*r2));
        double s = sin(a)*r1*r2;///四边形面积
        double b = acos((r1*r1+d*d-r2*r2)/(2*r1*d));
        double s1 = b * r1 * r1;///r1这边的扇形面积;
        double c = acos((r2*r2+d*d-r1*r1)/(2*r2*d));
        double s2 = c * r2 * r2;///r2这边的扇形面积;
        double ans = s1 + s2 - s;

        printf("Case %d: %.7f\n", t++, ans);
    }
    return 0;
}
/*
Input:
5
0 0 1 10 10 1
0 0 10 0 0 5
-862 823 894 -667 402 663
548 518 145 119 828 620
777 499 712 479 314 967

Output:
Case 1: 0.0
Case 2: 78.5398163397
Case 3: 1139058.0639436883
Case 4: 56622.85922574766
Case 5: 1513681.0685423985
*/
View Code

 

LightOj1118 - Incredible Molecules(两圆的交集面积)

标签:

原文地址:http://www.cnblogs.com/zhengguiping--9876/p/5768066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!