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. Linux 内核驱动--多点触摸接口【转】

    转自:http://blog.csdn.net/joard_yang/article/details/6225937 译自:linux-2.6.31.14/Documentation/input/mu ...

  2. Task多线程进行多进程

    using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...

  3. sql loader 控制文件使用十六进制分隔符

    最近项目中使用到了sql loader加载数据文件至数据库,提供的文件中使用了十六进制 7F5E 分隔符,在sql loader中如何加载呢? 经过查询实验后,控制文件ctl内容如下: load da ...

  4. spring单元测试的基本配置

    @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:trade.ap ...

  5. CSS3小黄人

    CSS3实现小黄人 效果图: 代码如下,复制即可使用: <!DOCTYPE HTML> <HTML> <head> <title>CSS3实现小黄人&l ...

  6. gtk+学习笔记(五)

    今天继续做的是昨天那个界面对的优化,直接贴下代码, void click_radio(GtkWidget *widget,gpointer *data) { 3 GtkWidget *dialog; ...

  7. Java MongoDB : Save image example

    In this tutorial, we show you how to save an image file into MongoDB, via GridFS API. The GridFS API ...

  8. 结合Python代码介绍音符起始点检测 (onset detection)

    本文由 meelo 原创,请务必以链接形式注明 本文地址 音符起始点检测介绍 音符起始点检测(onset detection)是音乐信号处理中非常重要的一个算法.节拍和速度(tempo)的检测都会基于 ...

  9. python根据字典自动生成一组省和市名

    字典如下: dict={ '河北省':['石家庄','唐山','秦皇岛','承德'], '山东省':['济南','青岛','临沂','淄博'], '湖南省':['长沙','衡阳','湘潭','邵阳', ...

  10. bzoj 1211: [HNOI2004]树的计数

    prufer的应用.. 详细见这篇博客:https://www.cnblogs.com/dirge/p/5503289.html import java.math.BigInteger; import ...