HDU 1798 Tell me the area (计算几何)

Tell me the area

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

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

2008 “Insigma International Cup” Zhejiang Collegiate Programming Contest - Warm Up(4)

Recommend

wangye   |   We have carefully selected several similar problems for you:  1797 1793 1796 1795 1794

利用余弦公式计算出角度,然后通过扇形和三角形的关系求出答案即可

#include<cmath>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
double distance(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    //freopen("in.txt","r",stdin);
    double PI=2*asin(1.0);
    double x1,y1,r1;
    double x2,y2,r2;
    double dis,r,cosa,cosb;
    double a,b,c,d,ans;
    while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF)
    {
        dis=distance(x1,y1,x2,y2);
        if(dis>=r1+r2||r1==0||r2==0)//两圆相离,外切时,相交面积为0
            ans=0;
        else if(dis<=fabs(r1-r2))//两圆内含,内切时,相交面积为较小圆的面积
        {
            r=r1<r2?r1:r2;
            ans=r*r*PI;
        }
        else//两圆相交时
        {
            cosa=acos((r1*r1+dis*dis-r2*r2)/(2*r1*dis));
            cosb=acos((r2*r2+dis*dis-r1*r1)/(2*r2*dis));//余弦公式求出两圆连线和半径的夹角
            a=r1*r1*cosa;
            b=r2*r2*cosb;//扇形面积
            c=r1*r1*cos(cosa)*sin(cosa);
            d=r2*r2*cos(cosb)*sin(cosb);//三角形面积
//            s1=0.5*r1*r1*(cos1-sin(cos1));
//            s2=0.5*r2*r2*(cos2-sin(cos2));
            ans=(a+b)-(c+d);//这里用两个扇形的面积之和减去三角形之和,是因为相交的情况分为两个圆的圆心是否在同一个圆里两种情况
        }
        printf("%.3lf\n",ans);
    }
    return 0;
}

HDU 1798 Tell me the area (计算几何)

时间: 2024-11-09 19:31:16

HDU 1798 Tell me the area (计算几何)的相关文章

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is

HDU 3103 Shoring Up the Levees(计算几何 搜寻区域)

主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103 Problem Description The tiny country of Waterlogged is protected by a series of levees that form a quadrilateral as shown below: The quadrilateral is defined by four vertices. The levees partition t

HDU 3103 Shoring Up the Levees(计算几何 求面积)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103 Problem Description The tiny country of Waterlogged is protected by a series of levees that form a quadrilateral as shown below: The quadrilateral is defined by four vertices. The levees partition t

hdu - 5128 The E-pang Palace(枚举+计算几何)

http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以的,面积就为大矩形的面积. 我是枚举一条对角线,然后去找另外两个点是否在坐标中存在这样就可以确定一个矩形, 同理可以枚举出另外有一个矩形,但是要注意坐标不能重复, 判断矩形相交的话,只要判断一个矩形的4个点是否有在另一个矩形的范围内即可. 1 #include<cstdio> 2 #include

POJ 1654 Area 计算几何

#include<stdio.h> #include<string.h> #include<iostream> #include<math.h> using namespace std; int dx[10]={0,1,1,1,0,0,0,-1,-1,-1}; int dy[10]={0,-1,0,1,-1,0,1,-1,0,1}; char s[1000010]; __int64 area,x,y,px,py; int main() { int sum,t

HDU 6697 Closest Pair of Segments (计算几何 暴力)

2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description The closest pair of points problem is a well-known problem of computational geometry. In this problem, you are given \(n\) points in the Euclidean plan

HDU 5533 Dancing Stars on Me 计算几何瞎暴力

Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1184    Accepted Submission(s): 651 Problem Description The sky was brushed clean by the wind and the stars were cold in a b

【HDU 1687】Lucky Light(思维+计算几何)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1687 题意:有一个光源,下面有很多放置的板子,问光线被板子分割之后在地上能产生多少块亮区(看题中的图就能看懂). 分析:这个题的做法和省选第一天的C题很像,由于是求在地面上,也就是一条直线上的亮区,我们可以求出地面上被木板遮挡形成的暗区的左坐标和右坐标,然后合并区间就可以了.而求地面上的坐标,可以用相似三角形,若光源为(sx,sy),点为(x1,y1)和(x2,y2),则地面上的坐标为:sx-(sx-

[ZOJ 1010] Area (计算几何)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 题目大意:给你n个点,问你顺次连线能否连成多边形?如果能,就输出多边形面积. 面积用向量的叉积去算.然后能否连成多边形就是看这条线跟之前的线有没有交点. 这些在大白书上都有板子.. 代码: 1 #include <cstdio> 2 #include <cstdlib> 3 #include <string> 4 #include