• hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)


    两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积

    画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交

    Sample Input
    2
    2 3
    0 0
    0 0
    2 3
    0 0
    5 0

    Sample Output
    Case #1: 15.707963
    Case #2: 2.250778

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <string>
     6 # include <cmath>
     7 # include <queue>
     8 # include <list>
     9 # define LL long long
    10 using namespace std ;
    11 
    12 const double eps = 1e-8;
    13 const double PI = acos(-1.0);
    14 
    15 struct Point
    16 {
    17     double x,y;
    18     Point(){}
    19     Point(double _x,double _y)
    20     {
    21         x = _x;y = _y;
    22     }
    23     Point operator -(const Point &b)const
    24     {
    25         return Point(x - b.x,y - b.y);
    26     }
    27     //叉积
    28     double operator ^(const Point &b)const
    29     {
    30         return x*b.y - y*b.x;
    31     }
    32     //点积
    33     double operator *(const Point &b)const
    34     {
    35         return x*b.x + y*b.y;
    36     }
    37     //绕原点旋转角度B(弧度值),后x,y的变化
    38     void transXY(double B)
    39     {
    40         double tx = x,ty = y;
    41         x = tx*cos(B) - ty*sin(B);
    42         y = tx*sin(B) + ty*cos(B);
    43     }
    44 };
    45 
    46 //*两点间距离
    47 double dist(Point a,Point b)
    48 {
    49     return sqrt((a-b)*(a-b));
    50 }
    51 
    52 //两个圆的公共部分面积
    53 double Area_of_overlap(Point c1,double r1,Point c2,double r2)
    54 {
    55     double d = dist(c1,c2);
    56     if(r1 + r2 < d + eps)return 0;
    57     if(d < fabs(r1 - r2) + eps)
    58     {
    59         double r = min(r1,r2);
    60         return PI*r*r;
    61     }
    62     double x = (d*d + r1*r1 - r2*r2)/(2*d);
    63     double t1 = acos(x / r1);
    64     double t2 = acos((d - x)/r2);
    65     return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
    66 }
    67 
    68 int main()
    69 {
    70     //freopen("in.txt","r",stdin) ;
    71     int T ;
    72     scanf("%d" , &T) ;
    73     int Case = 0;
    74     while(T--)
    75     {
    76         Case++ ;
    77         double r , R ;
    78         double x1 , y1 , x2 , y2 ;
    79         scanf("%lf%lf%lf%lf%lf%lf" , &r , &R , &x1 , &y1 , &x2 , &y2) ;
    80         Point c1(x1 ,y1) ;
    81         Point c2(x2 ,y2) ;
    82         double ans = 0 ;
    83         ans = Area_of_overlap(c1,R,c2,R) + Area_of_overlap(c1,r,c2,r);
    84         ans -= Area_of_overlap(c1,r,c2,R) ;
    85         ans -= Area_of_overlap(c1,R,c2,r) ;
    86         printf("Case #%d: %.6lf
    " , Case , ans) ;
    87 
    88     }
    89     return 0;
    90 }
    View Code
  • 相关阅读:
    XML 树操作 语法
    重构:第一个案例
    敏捷开发 慨叙
    sql server 字段类型
    Linux Win7双系统安装
    IE6/7不读取CSS样式,或不能正常显示背景图片问题
    eclipse 添加字体
    eclipse中测试Hibernate异常报 ORA00926: 缺失 VALUES 关键字
    关于简历的想法几点
    eclipse中测试Hibernate异常报'hibernate.dialect' must be set when no Connection avalable
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4850815.html
Copyright © 2020-2023  润新知