Intersection

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

Total Submission(s): 602 Accepted Submission(s): 247

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

题意

给你两个完全一样的圆环,圆环,圆环

因为很重要,所以要说三遍

然后求他们相交的面积

题解

那就直接套模板吧!!!

套板大作战,相交面积=大圆交-2*大小交+小交

代码

#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
typedef long long ll;
struct Point
{
double x,y;
Point (double x=0,double y=0):x(x),y(y){}
};
double dist(Point a,Point b)
{
double x=(a.x-b.x)*(a.x-b.x);
double y=(a.y-b.y)*(a.y-b.y);
return sqrt(x+y);
}
double Area_of_overlap(Point c1,double r1,Point c2,double r2)
{
double d=dist(c1,c2);
if (r1+r2<d+exp) return 0;
if (d<fabs(r1-r2)+exp)
{
double r=min(r1,r2);
return PI*r*r;
}
double x=(d*d+r1*r1-r2*r2)/(2*d);
double t1=acos(x/r1);
double t2=acos((d-x)/r2);
return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
}
int main()
{
int t,ncase=1;
double r,R;
Point a,b;
scanf("%d",&t);
while (t--)
{
scanf("%lf%lf",&r,&R);
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
double bb_area=Area_of_overlap(a,R,b,R);
double bs_area=Area_of_overlap(a,R,b,r);
double ss_area=Area_of_overlap(a,r,b,r);
printf("Case #%d: %.6lf\n",ncase++,bb_area-2.0*bs_area+ss_area);
}
return 0;
}

hdoj 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. hdu 5120 Intersection (圆环面积相交->圆面积相交)

    Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...

  3. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

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

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

  5. 三角剖分求多边形面积的交 HDU3060

    //三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...

  6. hdu1255 覆盖的面积 线段树+里离散化求矩形面积的交

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1 ...

  7. 光线求交-面、三角形、球 (Ray intersection)

    光线求交 光线定义:position \(a(t)\) = \(o\) + \(t\vec{d}\); 球定义: center p, radius r; 平面定义:normal \(\vec{n}\) ...

  8. hdu 5120 Intersection

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

  9. [NetTopologySuite](2)任意多边形求交

    任意多边形求交: private void btnPolygon_Click(object sender, EventArgs e) { , , , , , , , , , , , , , }; , ...

随机推荐

  1. WindowsServer2003双网卡配置

    今天突然被问起,找资料10+分钟才找到记录,因此再次记录下: route -p delete 0.0.0.0 route -p add 0.0.0.0 mask 0.0.0.0 58.240.115. ...

  2. Linux input子系统学习总结(一)---- 三个重要的结构体

    一 . 总体架构 图 上层是图形界面和应用程序,通过监听设备节点,获取用户相应的输入事件,根据输入事件来做出相应的反应:eventX (X从0开始)表示 按键事件,mice 表示鼠标事件 Input ...

  3. http请求中的中文乱码问题

    通过浏览器访问服务器页面和资源时,不可避免地要传送中文字串,如果客户机与服务器不能用同一码表解析字串,肯定会出现各种各样的乱码问题.我总结了几个乱码场景及解决办法,如下 1.服务器上的中文字串被客户端 ...

  4. centos 升级linux内核

    =============================================== 2018/1/14_第1次修改                       ccb_warlock == ...

  5. Python列表(list)

    序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. 此外,Python已经内置确定序列的长度以及确定最大和最小的元素 ...

  6. 转:vue-cli的webpack模板项目配置文件分析

    转载地址:http://blog.csdn.net/hongchh/article/details/55113751 一.文件结构 本文主要分析开发(dev)和构建(build)两个过程涉及到的文件, ...

  7. git clone命令使用

    git clone命令使用 分类: 项目构建2013-06-26 15:43 38660人阅读 评论(2) 收藏 举报 GitClone git clone 命令参数: usage: git clon ...

  8. Mat结构

    主要是记录一下大牛的博客,再次感谢这些无私的博主. 这篇博客http://blog.csdn.net/yang_xian521/article/details/7107786中,我觉得要注意的是Mat ...

  9. 洛谷P3367并查集

    传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  10. 奇妙的CSS之伪类与伪元素

    我们都知道,在CSS中有很多选择器,例如id(#), class(.),属性[attr],这些虽然可以满足一些需要,但有时候还力有未逮.伪类和伪元素就提供了一个有益的补充,可以使我们更高效编码.伪类和 ...