描述

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/(*r1*d);
double A=acos(coshalfA)*1.0/pi**;
shan1=A*pi*r1*r1/360.0;
a1=r1*r1*0.5*sin(A*pi/); double coshalfB=(r2*r2+d*d-r1*r1)*1.0/(*r2*d);
double B=acos(coshalfB)/pi**;
shan2=B*pi*r2*r2*1.0/;
a2=r2*r2*0.5*sin(B*pi/); s=s1+s2-(shan1+shan2-a1-a2);
}
printf("%.3f\n",s);
}
return ;
}

【TOJ 1449】Area of Circles II(求不同位置的两圆面积之和)的更多相关文章

  1. [LeetCode] Two Sum II - Input array is sorted 两数之和之二 - 输入数组有序

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  2. 167. Two Sum II - Input array is sorted两数之和

    1. 原始题目 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明 ...

  3. 167 Two Sum II - Input array is sorted 两数之和 II - 输入有序数组

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数.函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2.请注意,返回的下标值(i ...

  4. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 【二叉树-所有路经系列(根->叶子)】二叉树的所有路径、路径总和 II、路径总和、求根到叶子节点数字之和(DFS)

    总述 全部用DFS来做 重点一:参数的设置:为Root,路径字符串,路径List集合. 重点二:步骤: 1 节点为null 2 所有节点的操作 3 叶子结点的操作 4 非叶节点的操作 题目257. 二 ...

  6. Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted)

    Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted) 给定一个已按照升序排列 的有序数组,找到两个数使得它们 ...

  7. [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  8. VB求最大公约数的两个例子

    VB求最大公约数的两个算法 Private Sub Command1_Click() Dim a As Long, b As Long a = InputBox("请输入要求最大公约数的整数 ...

  9. 【Python实践-1】求一元二次方程的两个解

    知识点: import sys, sys模块包含了与Python解释器和它的环境有关的函数. “sys”是“system”的缩写.sys.exit() 中途退出程序, (注:0是正常退出,其他为不正常 ...

随机推荐

  1. 数组和矩阵(1)——Find the Duplicate Number

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  2. 为什么C语言会有头文件

    前段时间一个刚转到C语言的同事问我,为什么C会多一个头文件,而不是像Java和Python那样所有的代码都在源文件中.我当时回答的是C是静态语言很多东西都是需要事先定义的,所以按照惯例我们是将所有的定 ...

  3. IO流之递归

    递归: 递归,指在当前方法内调用自己的这种现象 public void method(){ System.out.println(“递归的演示”); //在当前方法内调用自己 method(); } ...

  4. Datatable paging,Repeater with Paging

    /// <summary> /// 塗聚文 /// 20140225 /// </summary> public partial class DatatablePage : S ...

  5. -ms-zoom property

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 五校联考模拟赛Day2T2矩阵(容斥原理)

    题意 $n * m$的网格,对其进行黑白染色,问每一行每一列至少有一个黑格子的方案数. Sol 考场上只会$n^3$的dp,还和指数级枚举一个分qwq 设$f[i][j]$表示到了第$i$行,已经有$ ...

  7. JavaWeb_01_html基本学习

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...

  8. Cass和ArcGIS交换

    南方cass图形为CAD,把CAD图形转换成arcgis没有任何问题,到属性有问题,cass存放数据是放在CAD扩展XDATA中,和 arcgis导入导出CAD标准扩展属性不一样,只能二次开发使用,c ...

  9. 使用HTML5 canvas做地图(2)瓦片以及如何计算的

    上一篇也说到瓦片,我们为什么使用瓦片?这一篇主要是关于如何拼接地图? 下面的一张图,可以一眼明了,地图是如何切割以及拼接的. 瓦片信息 瓦片信息包括切图原点,瓦片大小,格式,分辨率以及分辨率级别等. ...

  10. Informatica 9.1.0 Domain地址变化修改

    由于公司机房的变动,infa所连数据库的IP地址变化,致使INFA不能启动.经过查找资料终于解决,现分享给大家,解决方法如下: 1.查看日志路径: Informatica/9.1.0/tomcat/l ...