【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/(*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(求不同位置的两圆面积之和)的更多相关文章
- [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 ...
- 167. Two Sum II - Input array is sorted两数之和
1. 原始题目 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明 ...
- 167 Two Sum II - Input array is sorted 两数之和 II - 输入有序数组
给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数.函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2.请注意,返回的下标值(i ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 【二叉树-所有路经系列(根->叶子)】二叉树的所有路径、路径总和 II、路径总和、求根到叶子节点数字之和(DFS)
总述 全部用DFS来做 重点一:参数的设置:为Root,路径字符串,路径List集合. 重点二:步骤: 1 节点为null 2 所有节点的操作 3 叶子结点的操作 4 非叶节点的操作 题目257. 二 ...
- Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted)
Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted) 给定一个已按照升序排列 的有序数组,找到两个数使得它们 ...
- [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 ...
- VB求最大公约数的两个例子
VB求最大公约数的两个算法 Private Sub Command1_Click() Dim a As Long, b As Long a = InputBox("请输入要求最大公约数的整数 ...
- 【Python实践-1】求一元二次方程的两个解
知识点: import sys, sys模块包含了与Python解释器和它的环境有关的函数. “sys”是“system”的缩写.sys.exit() 中途退出程序, (注:0是正常退出,其他为不正常 ...
随机推荐
- svn自动更新网站代码
运行环境说明:svn的执行目录: /usr/bin/svnsvn版本库目录: /usr/local/nginx/html/svnrepos/coinhello (其中svnrepos是我各个项目版本库 ...
- Hadoop的安装与配置(虚拟机中的伪分布模式)
1引言 hadoop如今已经成为大数据处理中不可缺少的关键技术,在如今大数据爆炸的时代,hadoop给我们处理海量数据提供了强有力的技术支撑.因此,了解hadoop的原理与应用方法是必要的技术知识. ...
- ImageLoader简单使用
效果图就是一个从网络加载的图片:在加载的时候图片的中间显示一个进度条 数据是随便找的一个网络图片的地址 导入jar包universal-image-loader-1.9.5 用来展示商品使用 在 ...
- 我的SublimeText配置
我的SublimeText改键 [ /** * 我的改键 */ // f1控制中心:f2快速查找:f3查找下一个: { "keys": ["f1"], &quo ...
- How To Capture Packets with TCPDUMP?
http://linux-circles.blogspot.com/2012/11/how-to-capture-packets-with-tcpdump.html See the list of i ...
- oracle数据库建表设置自增主键
create sequence userlogin_ID increment by 1 start with 1 minvalue 1 maxvalue 9999999999999999 nocach ...
- June 01st 2017 Week 22nd Thursday
Do what you say, say what you do. 做你说过的,说你能做的. Do what I have said, live up to my promise, answer th ...
- 抓取android系统日志_记录一次定位app闪退故障
在测试android客户端兼容性时,发现app闪退,上海的小伙伴需要闪退时的系统日志:故把快生锈的adb知识拿出来show一把: 1.下载adb工具包(adb的全称为Android Debug Bri ...
- 关于表空间、Schema和用户
数据库这个柜子 解释数据库.表空间.数据文件.表.数据的最好办法就是想象一个装满东西的柜子. 从物理方面来讲:数据库是柜子,柜中的抽屉是表空间,抽屉中的文件夹是数据文件,文件夹中的纸是表,写在纸上的信 ...
- OC 内存管理(retain和release)
内存管理 retain和release简单使用 #import "Student.h" @implementation Student @synthesize age = _age ...