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);
        }
    }
  • 相关阅读:
    django.db.utils.OperationalError: (1050, "Table '表名' already exists)解决方法
    MySQL创建数据库与创建用户以及授权
    ubantu安装mysql
    sed命令详解
    docker-compose教程(安装,使用, 快速入门)
    Hive bucket表
    hive分区(partition)简介
    HIve实战分析Hadoop的日志
    hive 元数据解析
    hive学习笔记之-数据类型
  • 原文地址:https://www.cnblogs.com/mayouyou/p/9030693.html
Copyright © 2011-2022 走看看