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. Multiple methods named 'status' found with mismatched result, parameter type or attributes

    出现这个这个错误, 有可能是由于你直接通过一个数组的索引获取一个对象(或模型)然后直接调用这个对象(或模型)的某个方法 例如: NSString *status = [self.models[inde ...

  2. css滚动条样式

    1.横向滚动条:(abeamScroll) <div style="width:400px;height:200px;overflow-x:auto;overflow-y:hidden ...

  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost'

    # /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysq ...

  4. (转) oc static extern 和const

    static 全局的,可以改的,如果在一个类中声明static,类中其他地方用到的时候,也是使用的改变量.和java类似,但不能用类名直接访问. const 是常量,不可以改的 extern 1.假如 ...

  5. session绑定线程

  6. 《sort帮你排序》-linux命令五分钟系列之二十六

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  7. win7的IE11降到IE8

    我为什么要降低IE版本呢?...... 下载了抓包工具HttpWatch,下载地址http://pan.baidu.com/s/1kVhPMmj  版本如下: 用IE11打开抓包时流内没有内容,可能跟 ...

  8. wamp的mysql密码修改

    ==方法1== 通过WAMP打开mysql控制台,提示输入密码,因为现在是空,所以直接按回车. 输入“use mysql”,意思是使用mysql这个数据库教程,提示“Database changed” ...

  9. Android Context创建过程

        特定的资源或者类构成了Android应用程序的运行上下文环境 PackageManager, ClassLoader, Assert等等 Android应用程序窗口的运行上下文环境是通过Con ...

  10. 简单vim配置

    对于一个学习C++的人来说,我常用VS写代码,而Linux环境也是很重要的.最近学习了Linux的一些基本内容后,开始了vim编辑器的使用.然而它刚开始的界面着实令人很不习惯~~~于是我尝试着把它装饰 ...