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   容斥原理很明显,圆交的求法是我自己想的,很简单。
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int T,cas,r,R,px,py,qx,qy;
const double Pi=acos(-1.0);
double sqr(double x){return x*x;}
double Q(double r1,double r2){
double d=sqrt(sqr(px-qx)+sqr(py-qy));
if(r1+r2<=d)return ;
if(r1-r2>=d)return Pi*sqr(r2);
double a1=acos((sqr(r1)+sqr(d)-sqr(r2))/(*r1*d));
double a2=acos((sqr(r2)+sqr(d)-sqr(r1))/(*r2*d));
double s1=sqr(r1)*a1;
double s2=sqr(r2)*a2;
return s1+s2-r1*sin(a1)*d;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&r,&R);
scanf("%d%d%d%d",&px,&py,&qx,&qy);
printf("Case #%d: %.6lf\n",++cas,Q(R,R)-*Q(R,r)+Q(r,r));
}
return ;
}

计算几何(容斥原理,圆交):HDU 5120 Intersection的更多相关文章

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

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

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

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

  3. hdu 5120 Intersection 圆环面积交

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

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

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

  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 (圆环面积相交->圆面积相交)

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

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

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

  8. Intersection(HDU5120 + 圆交面积)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面 ...

  9. HDU 3467 Song of the Siren(圆交)

    Problem Description In the unimaginable popular DotA game, a hero Naga Siren, also known as Slithice ...

随机推荐

  1. 数据操作So easy-LINQ解析

    1.LINQ是什么? LINQ是Language Integrated Query的缩写,即“语言集成查询”的意思.LINQ的提出就是为了提供一种跨越各种数据源的统一的查询方式,它主要包含4个组件-- ...

  2. 不一样的编码风格--Lambda表达式

    Lambda表达式也是C#3.0中最重要的特性之一. 1.Lambda表达式的简介 Lambda表达式可以理解为一个匿名方法,它可以包含表达式和语句,并且用于创建委托或转换为表达式树.在使用Lambd ...

  3. 深入理解Javascript之this关键字

    深入理解Javascript之this关键字 作者: Laruence(   ) 本文地址: http://www.laruence.com/2009/09/08/1076.html 转载请注明出处 ...

  4. js和css分别实现透明度的动画实现

    js实现 两个函数 即setInterval和setTimeout setTimeout((function(){})(1/10),1*100) 该函数有两个参数,第一个为执行的函数,第二个为事件参数 ...

  5. 两款web api 调试工具

    两款web api 调试工具: Fiddler (http://www.telerik.com/fiddler) Postman(http://www.getpostman.com/) 资源: Fid ...

  6. android软件开发之webView.addJavascriptInterface循环渐进【二】

    本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gra ...

  7. 浅析JAVA设计模式(三)

    4.接口隔离原则: ISP(Interface Segregation Principle)  客户端不应该依赖它不需要的接口,或者说类的依赖的关系应该建立在最小的接口上.举个例子,直接上代码:  1 ...

  8. JS脚本延时

    JS脚本延时   function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7 ...

  9. 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制

    1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...

  10. appium的安装过程(图文界面)

    资料来源:http://www.cnblogs.com/fnng/p/4560298.html 1.准备安装材料