hdu 5120 圆和圆交面积模板

来源:互联网 发布:北京好的设计公司知乎 编辑:程序博客网 时间:2024/05/17 06:38

简单的集合题...关键是板子....

#include <iostream>

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define repf(i,a,b) for(int i=(a);i<=(b);i++)

using namespace std;

typedef long long LL;
const double PI = 3.141592653;

/*struct Round
{
    double x , y;
    double r;
}r[4];

double dis ( Round a , Round b )
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

double solve ( Round a , Round b )
{
    double d = dis(a,b);
    if ( d >= a.r + b.r ) return 0;
    if ( d <= fabs(a.r - b.r))
    {
        double r = a.r < b.r ? a.r : b.r;
        return PI * r * r;
    }
    double ang1 = acos((a.r * a.r + d * d - b.r * b.r)/2. / a.r / d );
    double ang2 = acos((b.r * b.r + d * d - a.r * a.r)/2. / b.r / d );
    double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1);
    return ret;
}*/

struct circle
{
    double x,y;
    double r;
}r[4];

double solve (point a,point b)
{
    double s,d,t,t1;
    d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    if(d>=a.r+b.r) s=0;
    else if(d<=fabs(a.r-b.r)) s=min(acos(-1.0)*a.r*a.r,acos(-1.0)*b.r*b.r);
    else
    {
        t=(a.r*a.r+d*d-b.r*b.r)/2.0/d;
        t1=sqrt(a.r*a.r-t*t);
        s=-d*t1+a.r*a.r*acos(t/a.r)+b.r*b.r*acos((d-t)/b.r);
    }
    return s;
}

int main ( )
{
    int t;
    double rr,R,x1,y1,x2,y2;
    scanf ( "%d" , &t );
    int c = 1;
    while ( t-- )
    {
       scanf ( "%lf%lf" , &rr , &R );
       scanf ( "%lf%lf" , &x1 , &y1 );
       scanf ( "%lf%lf" , &x2 , &y2 );
       r[1].r = r[3].r = rr;
       r[2].r = r[4].r = R;
       r[1].x = r[2].x = x1;
       r[1].y = r[2].y = y1;
       r[3].x = r[4].x = x2;
       r[3].y = r[4].y = y2;
       double ans = solve ( r[2] , r[4] );
       ans -= solve ( r[1] , r[4] );
       ans -= solve ( r[2] , r[3] );
       ans += solve ( r[1] , r[3] );
       printf ( "Case #%d: " , c++ );
       printf ( "%.6f\n" , ans );
    }
}



0 0
原创粉丝点击