【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是正常退出,其他为不正常 ...
随机推荐
- XHR的应用场景
一.简史 IE5.5最早实现XHR,需要通过ActiveXObject创建xhr实例,直到IE7才定义了XMLHttpRequest对象.IE5.5实现XHR之后,其他浏览器紧随其后实现了XHR,直接 ...
- linux下(ubuntu)反删除(误删恢复)与回收站制作
刚刚有个小伙伴不小心删了他写了好几的天代码,为他心疼之余帮他找回了文件. 想到我之前也常常误删一些文件,就干脆分享一下我的反删除方法,并说说我做的回收站(好low的,求大神指点) 首先是反删除软件ex ...
- with和catch改变作用域链
总结笔记: with和catch会将对象中标识符的解析添加到作用域链的最前端, 标识符的解析就是with()和catch()括号中的对象. var x = 10, y = 10; with ({x: ...
- C语言腾讯课堂(一)
腾讯课堂:c语言从零到精通 1. 从第一个例子开始 #include <stdio.h> int main(void) { printf("hello, qin men \n&q ...
- Java入门到精通——框架篇之Hadoop概述
一.Hadoop来历 Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明了倒排索引算法,通过加入了Map ...
- Java NIO(六) Selector
Selector(选择器)是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样,一个单独的线程可以管理多个channel,从而管理多个网络连接. 下面是 ...
- 用java实现一个简单的单用户登陆功能的思路
引用 所谓“单用户单账户登录”是指:在同一系统中,一个用户名不能在两个地方同时登录. 我们参照 QQ 实现效果:当某账号在 A 处登录后,在未退出的情况下,如果再到 B 处登录,那么,系统会挤下 A ...
- SqlServer50条常用查询语句
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...
- day012-Lambda、方法引用
1. 函数式接口 有且只有一个抽象方法的接口就是函数式接口. 函数式接口的定义格式: Interface 接口名{ 抽象方法: } @Override:用来修饰方法声明,告诉编译器该方法是重写父类的方 ...
- STM32-F429ZIT6-开发流程
---恢复内容开始--- 一.开发环境搭建 1.编译器安装破解 2.STM32Cube MX安装 3.驱动安装 4.固件库安装 二.硬件准备 1.PC 2.STM32开发板 3.下载线 三.资料准备 ...