zoukankan      html  css  js  c++  java
  • Area of Circles II(数论)

    描述

    There are two circles on the plane. Now you must to calculate the area which they cover the plane. For example, in Figure 1, the area of the red region is the answer of this problem.

    输入

    The input contains multiple test cases. The first line contains an integer T describing the number of test cases. Each case contains two lines. One line describes one circle. For each line has three integers x, y, r, indicating the coordinate of the centre and radius. All the numbers are separated by spaces. All the input integers are within the range of [-1000, 1000].

    输出

    For each test case, output one line containing a number with 3 digits after decimal point representing the answer describing above.

    样例输入

    2
    2 2 2
    1 4 3
    2 2 1
    -2 -2 1

    样例输出

    32.462
    6.283

    只能说是高中数学知识,模拟一下就完了。但是我好像把学得还回去了,结果想了好久好久。。。。。。

    #include<stdio.h>
    #include<math.h>
    double min(double a,double b)
    {
        if(a>b) a=b;
        return a;
    }
    double max(double a,double b)
    {
        if(a<b) a=b;
        return a;
    }
    int main()
    {
        double x1,x2,y1,y2,r1,r2,S;
        int n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2);
            double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
            double s1=acos(-1)*r1*r1;
            double s2=acos(-1)*r2*r2;
            if(d>=r1+r2) S=s1+s2;
            else if(d<=max(r1,r2)-min(r1,r2)) S=max(s1,s2);
            else
            {
                double A=2*acos((r1*r1+d*d-r2*r2)/(2*r1*d));
                double shan1=A*r1*r1/2;
                double sanjiao1=sin(A)*r1*r1/2;
                double B=2*acos((r2*r2+d*d-r1*r1)/(2*r2*d));
                double shan2=B*r2*r2/2;
                double sanjiao2=sin(B)*r2*r2/2;
                S=s1+s2-(shan1+shan2-sanjiao1-sanjiao2);
            }
            printf("%.3lf
    ",S);
        }
    }
  • 相关阅读:
    nginx过一段时间出现400 Bad Request 错误的解决方法
    log4j.properties的配置详解
    新手指南:Linux上vi(vim)编辑器使用教程
    JDK1.6在LINUX下的安装配置[转]
    Oracle中查看所有表和字段以及表注释.字段注释
    mybatis中使用in查询时的注意事项
    启动64位 IIS 32位应用程序的支持
    tar 打包命令
    类型强转和字节对齐
    emacs windows 下配置
  • 原文地址:https://www.cnblogs.com/mayouyou/p/9030693.html
Copyright © 2011-2022 走看看