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. iOS 图片按比例压缩,指定大小压缩

    使用系统方法UIImageJPEGRepresentation(UIimage *image,CGFloat quality)进行图片质量压缩,暂且叫参数quality为压缩比吧,取值范围为0-1. ...

  3. Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面

    Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面 关于欢迎界面 很多App第一次启动都会有一个欢迎界面,欢迎界面往往决定这用户对App的第一映像,所以欢 ...

  4. struts2框架加载配置文件的顺序

    struts-default.xml:该文件保存在struts2-core-x.x.x.jar文件中: struts-plugin.xml:该文件保存在 struts2-Xxx-x.x.x.jar等S ...

  5. java新手笔记22 接口示例2

    1.USB package com.yfs.javase; public interface USB { //定义规范 public void read(); public void write(); ...

  6. Java教程——CMD手动编译运行失败原因(高手略过)

    (仅对新手,高手略过)在学习Java初期,我们在利用cmd手动编译java程序的时候,会遇到编译成功,但运行却总是提示失败.已经排除了java配置环境的问题,Path和ClassPath以及%JAVA ...

  7. SpringMVC的文件上传

    首先导入jar包 在springMVC里面配置文件上传,以及限定上传文件的大小  <bean id="multipartResolver" class="org.s ...

  8. TFTPD32, 3CDaemon, FlashFxp

    TFTPD32, 3CDaemon, FlashFxp ——各种网络传输下载工具简介—— 一.将3CDaemon.exe作为TFTP服务端,开发板作为TFTP客户端 1.如上图所示,设置好3CDaem ...

  9. Library string type(2)——关于String的操作

    关于string的定义,请参阅博文http://blog.csdn.net/larry233/article/details/51483827 string的操作 s.empty() //Return ...

  10. hdu 1286 找新朋友 (欧拉函数)

    Problem Description 新年快到了,"猪头帮协会"准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的 ...