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. innobackupex 相关语法讲解【转】

    innobackupex 相关语法讲解 连接服务器 The database user used to connect to the server and its password are speci ...

  2. HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...

  3. 记录一下mariadb设置主从同步的过程[虚拟机测试]

    背景:因为工作的关系,需要找寻实时同步数据到另外系统的服务器的数据库上,查询下来,用mariadb进行跨服务器的同步数据动作,用主从同步比较多,也比较保险 也有使用shell脚本的,定时定候的执行my ...

  4. Python生成器-博文读后感

    Windows 10家庭中文版,Python 3.6.4, 上午看过了一篇讲Python生成器的博文: 提高你的Python: 解释‘yield’和‘Generators(生成器)’(英文原文) 这篇 ...

  5. No.2 selenium学习之路之八种基本定位

    selenium的八种定位方式 1.通过id定位     find_element_by_id() send_keys() 输入框输入字符串 click()  鼠标点击事件 注:send_keys输入 ...

  6. dpr 与 dproj 有什么区别

  7. tensorflow高级库

    1.tf.app.flags tf定义了tf.app.flags,用于支持接受命令行传递参数,相当于接受argv.tf.app.flags.DEFINE_xxx()就是添加命令行的optional a ...

  8. Redis(一)Redis简述

    一 Redis 概念 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,和Memcached类似,它支持存储的value类型相对更多,包 ...

  9. 【58沈剑架构系列】微服务架构之RPC-client序列化细节

    第一章聊了[“为什么要进行服务化,服务化究竟解决什么问题”] 第二章聊了[“微服务的服务粒度选型”] 上一篇聊了[“为什么说要搞定微服务架构,先搞定RPC框架?”] 通过上篇文章的介绍,知道了要实施微 ...

  10. js 格式化时间,可定义格式

    var format = function (time, format) { var t = new Date(time); var tf = function (i) { return (i < ...