Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.

A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.

Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.

 
Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).
Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
 
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
Sample Input
2
2 3
0 0
0 0
2 3
0 0
5 0
Sample Output
Case #1: 15.707963
Case #2: 2.250778
 
两个圆环相交,然而我只有圆相交的板子
首先拿其中一个大圆A与另一个大圆B和小圆b算交面积,两者相减,求的是A与圆环Bb相交的面积 area1
然后拿小圆a另一个大圆B和小圆b算交面积,两者相减,求的是a与圆环Bb相交的面积,area2
我们输出area1-area2就行了
 #include <bits/stdc++.h>

 using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-;
int dblcmp (double k)
{
if (fabs(k)<eps) return ;
return k>?:-;
}
struct Point
{
double x,y;
};
double dis (Point a,Point b)
{
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double area_of_overlap (Point c1,double r1,Point c2,double r2)//圆相交模板
{
double d = dis(c1,c2);
if (r1+r2<d+eps) return ;
if (d<fabs(r1-r2)+eps){
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d+r1*r1-r2*r2)/(*d);
double t1 = acos(x/r1);
double t2 = acos((d-x)/r2);
return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
}
int t;
int casee = ;
int main()
{
//freopen("de.txt","r",stdin);
scanf("%d",&t);
while (t--){
Point p1,p2;
double r1,r2;
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&p1.x,&p1.y);
scanf("%lf%lf",&p2.x,&p2.y);
if (dblcmp(r1-r2)>) swap(r1,r2);
double ans = area_of_overlap (p1,r2,p2,r2) -area_of_overlap (p1,r2,p2,r1)
-(area_of_overlap (p1,r1,p2,r2) - area_of_overlap(p1,r1,p2,r1) );
/*double ans = area (p1,r2,p2,r2) -area (p1,r2,p2,r1)
-(area(p1,r1,p2,r2) - area(p1,r1,p2,r1) );*/
printf("Case #%d: %.6f\n",++casee,ans);
}
return ;
}
 

hdu 5120 Intersection (圆环面积相交->圆面积相交)的更多相关文章

  1. hdu 5120 Intersection 圆环面积交

    Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  2. hdoj 5120 Intersection 圆环面积求交

    Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Tota ...

  3. hdu 5120(2014北京—求圆相交)

    题意:求环的相交面积 思路: 通过画图可知,面积= 大圆相交面积 - 大小圆相交面积*2 + 小小圆相交面积  再通过圆相交模板计算即可 #include <iostream> #incl ...

  4. HDU 5120 Intersection (圆的面积交)

    题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...

  5. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

  6. hdu 5120 Intersection 两个圆的面积交

    Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) P ...

  7. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  8. HDU 5120 Intersection(几何模板题)

    题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...

  9. 计算几何(容斥原理,圆交):HDU 5120 Intersection

    Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...

随机推荐

  1. P1040加分二叉树

    据说窝回去的那几天考了n次试 过去了一个月才想起来补锅 传送 首先来区分一下什么是中序遍历,什么又是前序遍历 中序遍历:左,根,右(也就是说给出一个序列(按照中序遍历的序列),第i个点左边的点都是i的 ...

  2. 大数据学习笔记之Zookeeper(四):Zookeeper实战篇(二)

    文章目录 4.1 分布式安装部署 4.2 客户端命令行操作 4.3 API应用 4.3.1 eclipse环境搭建 4.3.2 创建ZooKeeper客户端: 4.3.3 创建子节点 4.3.4 获取 ...

  3. sql 为什么要用where 1=1?

    之前一直不太明白,sql语句里为什么要写where 1=1 提升某种执行效率? 其实,1=1 是永恒成立的,意思无条件的,也就是说在SQL语句中有没有这个1=1都可以. 这个1=1常用于应用程序根据用 ...

  4. deepin下安装配置git

    https://blog.csdn.net/menglinjie/article/details/77145537 1.安装gitsudo apt-get install git12.配置用户名和邮箱 ...

  5. Python入门习题5.蒙特卡罗方法计算圆周率

    #CalPi.py from random import random from math import sqrt from time import clock DARTS = 10000000 hi ...

  6. jvm学习(5) 对象的创建与结构

    上图表明:jvm虚拟机位于操作系统的堆中,并且,程序员写好的类加载到虚拟机执行的过程是:当一个classLoder启动的时候,classLoader的生存地点在jvm中的堆,然后它会去主机硬盘上将A. ...

  7. 对于nginx配置文件中的fastcgi_param相关参数的理解

    今天在ubuntu中搭建LNMP的时候,遇到了一个问题 在浏览器中访问.php文件的时候,nginx不能正常解析,页面只是空白,后来百度了一下,发现了问题 在nginx的配置文件nginx.conf中 ...

  8. A Bug’s Life POJ - 2492(种类并查集)

    题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一 ...

  9. Linux scp常用命令

    Linux scp命令用于Linux之间复制文件和目录. scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令. 1.从本地复制到远程 命令格式: ...

  10. JS中 [] == ![]结果为true,而 {} == !{}却为false

     为什么? 先转换再比较      (==) 仅比较而不转换  (===) ==转换规则?   ==比较运算符会先转换操作数(强制转换),然后再进行比较 ①如果有一个操作数是布尔值,则在比较相等性之前 ...