poj 2546 Circular Area (两圆相交面积)

链接:poj 2546

题意:已知两圆的圆心和半径,求两圆相交部分的面积

分析:两圆的位置关系有三种:相离,相交,内含

相离时:相交面积为0

相交时,大扇形面积+小扇形面积-四边形面积

内含时,相交面积为小圆面积

#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
typedef struct stu
{
    double x,y;
}point;
double Distance(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double InterArea(point a,double R,point b,double r)
{
    if(R<r){
        double temp=R;
        R=r;
        r=temp;
    }
    double dis=Distance(a,b);
    if(dis>=R+r)    //两圆相离,相交面积为0
        return 0;
    if(dis<=R-r)    //两圆内含,相交面积为小圆的面积
        return PI*r*r;
    //两圆相交时
    double angle1=acos((R*R+dis*dis-r*r)/(2.0*R*dis));
    double angle2=acos((r*r+dis*dis-R*R)/(2.0*r*dis));
    double s=R*angle1*R+r*angle2*r;
    s-=R*dis*sin(angle1);
    return s;
}
int main()
{
    point a,b;
    double r1,r2;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&r1,&b.x,&b.y,&r2)!=EOF)
        printf("%.3lf\n",InterArea(a,r1,b,r2));
    return 0;
}
时间: 2024-10-20 05:48:04

poj 2546 Circular Area (两圆相交面积)的相关文章

POJ 2546 &amp; ZOJ 1597 Circular Area 两圆的面积交

Circular Area Time Limit: 2 Seconds      Memory Limit: 65536 KB Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of in

poj 2546 Circular Area 两圆面积交

题意: 给两个圆,求它们的面积交. 分析: 海伦公式,余弦定理等可解. 代码: //poj 2546 //sep9 #include <iostream> #include <cmath> using namespace std; const double pi=acos(-1.0); int main() { double x1,y1,r1,x2,y2,r2; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1

poj2546Circular Area(两圆相交面积)

链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; #include<cmath> #include<iomanip> #include<algorithm> int main() { double d,t,t1,s,x,y,xx,yy,r,rr; while(cin>>x>>y>>r) {

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

POJ 2546 Circular Area(两个圆相交的面积)

题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆心坐标(x2,y2). d为两圆圆心连线的长度. 相交面积为S d=sqrt((x1-x2)^2+(y1-y2)^2) (1)如果r1+r2<=d 那么两圆相离,相交面积S=0 (2)如果r2-r1>=d 那么半径小的圆内含半径大的圆,那么相交面积为小圆的面积S=pi*r1*r1 (3)既非(1)

poj 2546 Circular Area

Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of input file there are space-separated real numbers x1 y

[hdu 3264] Open-air shopping malls(二分+两圆相交面积)

题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右边没差别,红色的圆为答案(选了左边的圆点),它覆盖了左边圆的1/2以上,也覆盖了右边圆的1/2以上. 知道了怎样求两圆面积交.那么这道题就简单了.仅仅要二分答案,然后枚举每个圆点,假设全都覆盖了1/2以上就继续二分,最后答案就得出来了. #include<iostream> #include<

求两圆相交面积模板

#define PI 3.141592654 #define eps 1e-8 double getdis(int x1,int y1,int x2,int y2){ return sqrt((double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } double getarea(int x1,int y1,double r1,int x2,int y2,double r2){ double d=getdis(x1,y1,x2,y2); if(r1+r2<d+eps)

poj 2546(两圆公共面积)

Circular Area Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2225 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after