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.

InputThe first line contains only one integer T (T ≤ 10
5), 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 x
i, y
i (0 ≤ x
i, y
i ≤ 20) indicating the coordinates of the center of each ring.OutputFor 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
/*
题意:求两个圆环相交的面积 思路:圆环相交面积=外圆1与外圆2相交面积-内圆1与外圆2相交面积-外圆1与内圆2相交面积+内圆1与内圆2相交面积
*/
#include <bits/stdc++.h> #define MAXK 3
#define pi acos(-1) using namespace std; int t;
double r,R;
double x[MAXK],y[MAXK]; double dis(double a1,double b1,double a2,double b2){
return sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
} double cal(double a1,double b1,double R,double a2,double b2,double r){
double d=dis(a1,b1,a2,b2);
if(d>=(R+r)){
return 0.0;
}else if(d<=fabs(R-r)){
return min(pi*R*R,pi*r*r);
}else{
if(r>R){
swap(a1,a2);
swap(b1,b2);
swap(R,r);
}
double ok=sqrt(R*R-r*r);
double x=(R*R-r*r+d*d)/(*d);
x=sqrt(R*R-x*x);
double s1=acos(-(*x*x)/(*R*R));
double s2=acos(-(*x*x)/(*r*r));
if(d>=ok){//相交的很小
return (R*R*s1+r*r*s2-*d*x)/;
}else{//相交的很大
return pi*r*r-(r*r*s2-R*R*s1+*d*x)/;
}
} }
int main(){
//freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case #%d: ",ca);
scanf("%lf%lf",&r,&R);
for(int i=;i<;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
printf("%.6f\n",cal(x[],y[],R,x[],y[],R)-
cal(x[],y[],R,x[],y[],r)-
cal(x[],y[],r,x[],y[],R)+
cal(x[],y[],r,x[],y[],r));
}
return ;
}

I - Intersection HDU - 5120(圆环相交面积)的更多相关文章

  1. hdu5012 圆环相交面积

    题中给了 两个同心圆, 一个大圆一个小圆,然后再给了一个大圆一个小圆也是同心圆,求这两个圆环相交的面积,用两个大圆面积减去两倍大小圆面积交加上两个小圆面积交,就ok了 这里算是坑明白了 使用acos的 ...

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

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

  3. hdu 5120 Intersection (圆环面积相交->圆面积相交)

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

  4. hdu 5120 Intersection 圆环面积交

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

  5. hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)

    两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...

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

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

  7. hdu 5120 (求两圆相交的面积

    题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...

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

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

  9. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

随机推荐

  1. Doing Homework again

     Doing Homework again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  2. Greatest Common Increasing Subsequence hdu1423

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  3. hdu4614 线段树+二分 插花

    Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...

  4. Ubuntu16.04下安装redis

    Ubuntu16.04下安装redis 保证网络畅通,选定好下载工作路径,执行以下命令下载redis-3.2.6: sudo wget http://download.redis.io/release ...

  5. socket及其相关(续篇)

    IO 多路复用 基本概念 IO多路复用是指内核一旦发现进程指定的一个或者多个IO条件准备读取,它就通知该进程.IO多路复用适用如下场合: (1)当客户处理多个描述字时(一般是交互式输入和网络套接口), ...

  6. 编译期类型检查 in ClojureScript

    前言  话说"动态类型一时爽,代码重构火葬场",虽然有很多不同的意见(请参考),但我们看到势头强劲的TypeScript和Flow.js,也能感知到静态类型在某程度上能帮助我们写出 ...

  7. PHP 两张图片合成一张图片(加水印)

    $dst_im = 'http://www.wangshangyou.com/content/uploadfile/201312/b3241386050881.png'; $src_im = 'htt ...

  8. Python自学笔记-paramiko模块(Mr serven)

    文章出处:http://www.cnblogs.com/wupeiqi/articles/5095821.html SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: #!/u ...

  9. 翻译连载 | 第 10 章:异步的函数式(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇

    原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...

  10. BaseServlet,让一个servlet处理多个请求

    BaseServlet 第一次学习servlet的时候是跟着传智播客免费的教学视频,其中崔希凡讲的是我学过自认讲的最好的一位,BaseServlet也是跟着他写过一次,当时很多东西不能理解,后来慢慢发 ...