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\n",S);
    }
}

原文地址:https://www.cnblogs.com/mayouyou/p/9030693.html

时间: 2024-10-09 15:04:15

Area of Circles II(数论)的相关文章

【TOJ 1449】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 contai

UVA 11426 - GCD - Extreme (II) (数论)

UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N,求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gcd(1, n) + gcd(2, n) + ... + gcd(n - 1, n).这样的话,就可以得到递推式S(n) = f(2) + f(3) + ... + f(n) ==> S(n) = S(n - 1) + f(n);. 这样问题变成如何求f(n).设g(n, i),表示满足gcd(x, n)

UVA 11426 GCD - Extreme (II) (数论|欧拉函数)

题意:求sum(gcd(i,j),1<=i<j<=n). 思路:首先可以看出可以递推求出ans[n],因为ans[n-1]+f(n),其中f(n)表示小于n的数与n的gcd之和 问题转化为了求f(n),因为小于n的数与n的gcd一定是n的因数, 所以f(n)可以表示为sum(i)*i,其中sum(i)表示所有和n的gcd为i的数的数量,我们要求满足gcd(a, n) = i,的个数,可以转化为求gcd(a/i, n/i) = 1的个数, 于是可以发现sun(i) = phi(n/i),这

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

【转】[专题学习][计算几何]

原文地址:http://www.cnblogs.com/ch3656468/archive/2011/03/02/1969303.html 基本的叉积.点积和凸包等东西就不多说什么了,网上一搜一大堆,切一些题目基本熟悉了就差不多了. 一些基本的题目可以自己搜索,比如这个blog:http://blog.sina.com.cn/s/blog_49c5866c0100f3om.html 接下来,研究了半平面交,思想方法看07年朱泽园的国家队论文,模板代码参考自我校大牛韬哥: http://www.o

【转】An Intuitive Guide To Exponential Functions &amp; e

An Intuitive Guide To Exponential Functions & e e has always bothered me — not the letter, but the mathematical constant. What does it really mean? Math books and even my beloved Wikipedia describe e using obtuse jargon: The mathematical constant e i

SPOJ CIRU The area of the union of circles

You are given N circles and expected to calculate the area of the union of the circles ! Input The first line is one integer n indicates the number of the circles. (1 <= n <= 1000) Then follows n lines every line has three integers Xi Yi Ri indicate