• HDU 5120 Intersection


    Intersection
    Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
    Total Submission(s): 2699 Accepted Submission(s): 1011


    Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.

    A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.

    Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.


    Input The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

    Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.


    Output For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
    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


    Source 2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)
    解析:求两圆相交面积。画个图简单分析可知,圆环相交面积 = 两大圆相交面积-2*(大圆小圆相交面积)+小圆相交面积。注意两圆外离、外切和内含、内切的情况。
    ``` #include #include #include using namespace std;

    const double PI = acos(-1.0);
    struct Point
    {
    double x, y, r;
    } A, B, a, b;

    double dis(const Point &a, const Point &b)
    {
    return sqrt((a.x-b.x)(a.x-b.x)+(a.y-b.y)(a.y-b.y));
    }

    double interarea(Point a,Point b)
    {
    double d = dis(a, b);
    if(d >= a.r+b.r) //外离或外切
    return 0;
    double r = min(a.r, b.r);
    if(d <= fabs(a.r-b.r)) //内含或内切
    return PIrr;
    double angle1 = acos((a.ra.r+dd-b.rb.r)/2.0/a.r/d);
    double angle2 = acos((b.r
    b.r+dd-a.ra.r)/2.0/b.r/d);
    double ret = 0;
    ret -= da.rsin(angle1);
    ret += angle1a.ra.r+angle2b.rb.r;
    return ret;
    }
    int main()
    {
    int t, cn = 0;
    scanf("%d", &t);
    while(t--){
    double r,R,x1,y1,x2,y2;
    scanf("%lf%lf%lf%lf%lf%lf",&r,&R,&x1,&y1,&x2,&y2);
    A.r = R, a.r =r, A.x = a.x = x1, A.y = a.y = y1;
    B.r = R, b.r =r, B.x = b.x = x2, B.y = b.y = y2;
    double S = interarea(A,B);
    double s1 = interarea(a,B);
    // double s2=interarea(A,b);
    double s3 = interarea(a,b);
    // double res=S-(s1+s2-s3);
    double res = S-2*s1+s3;
    printf("Case #%d: %.6f ", ++cn, res);
    }
    return 0;
    }

  • 相关阅读:
    毕业设计:参考文献(3)
    毕业设计:参考文献(5)
    毕业设计:参考文献(1)
    毕业设计:参考文献(7)
    毕业设计:参考文献(2)
    2021ICPC沈阳站游记
    2021CCPC广州站游记
    常用linux 脚本
    Jenkins调优实践
    linux工具安装
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5990640.html
Copyright © 2020-2023  润新知