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. java web-----servelet

    1,定义servlet: 2,servlet生命周期: 3,HttpServlet常用方法: 4,servlet常用接口: 一,servlet定义: servlet是一个继承HttpServlet类的 ...

  2. 通过 OpenNI 建立 Kinect 3D Point Cloud

    這篇還是算延續前一篇的<透過 OpneNI 合併 Kinect 深度以及彩色影像資料>.在可以透過 OpenNI 讀取到 Kinect 的深度.色彩資訊之後,其實就可以試著用這些資訊,來重 ...

  3. demo——06弹性和制作骰子

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. php学习,一个简单的Calendar(1)

    材料取之深入PHP与JQuery开发,这本书实际上就是讲述一个活动日程表. 此文章适合从其它语言(如java,C++,python等)转到php,没有系统学习php,或者是php初学者,已经对程序有较 ...

  5. PHP-Wamp集成包安装教程

    在Windows平台上搭建PHP的开发环境可以下载WAMP(Windows.Apache.MySQL.PHP的首字母缩写)集成化安装包.这样就不需要单独安装Apache.MySQL和PHP了. 这款软 ...

  6. JS将搜索的关键字高亮显示实现代码

    这篇文章介绍了JS将搜索的关键字高亮显示实现代码,有需要的朋友可以参考一下 用JS让文章内容指定的关键字加亮 是这样的.. 现在有这些关键字:美容,生活,购物 当在文章里头出现这些关键字,就把它加亮显 ...

  7. XML2_XML的节点和元素

    在JAVA语言中使用JAXP操作XML文件的时候,有两个接口,一个是Node,一个是Element,Element接口继承自Node接口. 在这一层次我们进一步理解XML中更具体的分类: 元素,属性, ...

  8. hadoop1中mapreduce原理详解

    剖析Mapreduce作业运行机制:原理如下图: 原理图的解释的可以分为以下几个部分 1.客户端提交一个mapreduce的jar包给JobClient 2.JocClient通过RPC和JobTra ...

  9. Python学习_数据处理split方法

    用open方法导入文件“sketch.txt”后,用split()方法进行分割: >>> import os >>> os.chdir('C:/Python33/H ...

  10. BZOJ 1052: [HAOI2007]覆盖问题

    BZOJ 1052: [HAOI2007]覆盖问题 题意:给定平面上横纵坐标在-1e9~1e9内的20000个整数点的坐标,用三个大小相同边平行于坐标轴的正方形覆盖(在边界上的也算),问正方形的边长最 ...