描述

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. XML入门介绍(什么是XML及XML格式)

    什么是 XML? XML 指可扩展标记语言(EXtensible Markup Language). XML 是一种很像HTML的标记语言. XML 的设计宗旨是传输数据,而不是显示数据. XML 标 ...

  2. Jedis Cluster源码分析

    最近一个项目用到Jedis客户端,需要对这个客户端进行改造.看了一下Jedis Cluster源码,做个记录 首先,说核心内容, 在Jedis源码中,关于cluster有个两个重要的map.一个是no ...

  3. jquery toggle(listenerOdd, listenerEven)

    1. example: <!DOCTYPE HTML><html>    <head></head>    <body>        &l ...

  4. HTML 5中的新特性

    HTML 5中的新特性 html5新增了一些语义化更好的标签元素.首先,让我们来了解一下HTML语义化. 1.什么是HTML语义化? 根据内容的结构化(内容语义化),选择合适的标签(代码语义化)便于开 ...

  5. 刚在虚拟机上装的Linux系统,ifconfig后IP地址怎么成了127.0.0.1了

    之前在虚拟机上装了Linux系统,用了一段时间后想删除了重新装一下,然而装完以后ifconfig后,出现的是 [root@localhost ~]# ifconfig lo Link encap:Lo ...

  6. 【IOS】Mac和IOS开发资源汇总

    本文主要汇集一些苹果开发的资源,会经常更新,建议大家把这篇文章单独收藏(在浏览器中按**command+D**). 今天收录了许多中文网站和博客.大家一定要去感受一下哦. 如果大家有知道不错的站点,可 ...

  7. python闭包&装饰器&偏函数

    什么是闭包? 首先还得从基本概念说起,什么是闭包呢?来看下维基上的解释: 在计算机科学中,闭包(Closure)是词法闭包(Lexical Closure)的简称,是引用了自由变量的函数.这个被引用的 ...

  8. XP环境安装request包报错:离线安装packages: certifi urllib3 idna chardet

    分别下载 request certifi urllib3 idna chardet 安装包 数据包下载地址:https://pypi.org/ 解压到python安装目录 使用cmd命令进入..\py ...

  9. Intel® Manager for Lustre* software(一)

    Intel® Manager for Lustre* software Installation 软件安装指导目录: 安装IML(Intel® Manager for Lustre* software ...

  10. mysql导入csv格式文件

    今天测试导入csv格式文件,虽然简单但是如果不注意还是会出现错误,而且mysql在某些方面做的确实对新手不是很友好,记录一下:创建一个csv格式文件:[mysql@xxx1 ycrdb]$ more ...