【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 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<bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;
int main()
{
    int t;
    double x1,y1,r1,x2,y2,r2,s,d,a1,a2,s1,s2,shan1,shan2;
    cin>>t;
    while(t--)
    {
        cin>>x1>>y1>>r1>>x2>>y2>>r2;
        d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

        if(r1>r2)
            swap(r1,r2),swap(x1,x2),swap(y1,y2);

        s1=pi*r1*r1;
        s2=pi*r2*r2;

        if(d>=r1+r2)
            s=s1+s2;
        else if(d<=r2-r1)
            s=s2;
        else
        {
            double coshalfA=(r1*r1+d*d-r2*r2)*1.0/(2*r1*d);
            double A=acos(coshalfA)*1.0/pi*180*2;
            shan1=A*pi*r1*r1/360.0;
            a1=r1*r1*0.5*sin(A*pi/180);

            double coshalfB=(r2*r2+d*d-r1*r1)*1.0/(2*r2*d);
            double B=acos(coshalfB)/pi*180*2;
            shan2=B*pi*r2*r2*1.0/360;
            a2=r2*r2*0.5*sin(B*pi/180);

            s=s1+s2-(shan1+shan2-a1-a2);
        }
        printf("%.3f\n",s);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/kannyi/p/9011635.html

时间: 2024-10-23 16:27:53

【TOJ 1449】Area of Circles II的相关文章

【BZOJ3563/3569】DZY Loves Chinese II 线性基神题

[BZOJ3563/3569]DZY Loves Chinese II Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上有N座祭坛,又有M条膴蠁边. 时而Dzy狂WA而怒发冲冠,神力外溢,遂有K条膴蠁边灰飞烟灭. 而后俟其日A50题则又令其复原.(可视为立即复原) 然若有祭坛无法相互到达,Dzy之神力便会大减,于是欲知其是否连通. Input 第

【TOJ 3600】Fibonacci II (对数+斐波那契通项式)

描述 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来.接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了.所以规定超过4位的只要说出前4位就可以了,可是CodeStar自己又记不住.于是他决定编写一个程序来测验zouyu说的是否正确. 输入 输入若干数字n(0 <= n <=

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

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

【BZOJ 3569】DZY Loves Chinese II 随机化+线性基

用到一个结论——[先建树,再给每个非树边一个权值,每个树边的权值为覆盖他的非树边的权值的异或和,然后如果给出的边存在一个非空子集异或和为0则不连通,否则连通](必须保证每条边的出现和消失只能由自己产生,即一个边不能由其他其他边异或得到,这就是我们随机化边权的原因) 证明:(前置性质:I.只割非树边一定不可以 II.非树边"藏"在树边里 III.非树边是在树上是简单路径 IV.对于一个连通块(只考虑树结构),"藏"在他周围树边里的非树边要么连接他与外界(只在他周围树边

【TOJ 3005】Triangle(判断点是否在三角形内)

描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether the point is in the Triangle. 输入 The input contains several test cases. For each test case, only line contains eight integer numbers , describing the c

【TOJ 5255】C++实验:三角形面积(海伦公式)

描述 实现C++三角形类,其中包含3个点(CPoint类型),并完成求面积.主函数里的代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { CPoint p1, p2, p3; while(cin>>p1>>p2>>p3) { CTriangle t(p1, p2, p3); cout<<setiosflags(ios::fixed)<<setprecision(3)<<t.Area()<<e

【TOJ 2034】C++实验:面积排序(已知三点,利用二阶行列式求三角形面积)

描述 给定三角形.矩形.圆等二维几何图形,请根据面积从大到小进行排序. 主函数里的代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { vector<CShape*> vec; //为了使用多态,使用指针数组 string name; int num[3]= {}; //用于存储3种形状的ID while(cin>>name) { if(name=="rectangle") { CPoint p1, p2; cin>>p

【SG博弈】HDU 5299 Circles Game

通道:http://acm.hdu.edu.cn/showproblem.php?pid=5299 题意:n个不相交相切的圆,每次操作删圆及其内部的圆,不能删者败. 思路:建边,然后树上SG即可. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <set> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int MAX_N =