Intersection

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3018    Accepted Submission(s): 1135

Problem Description

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
 

Source

2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)

//题意:问两个同样大的圆环相交的面积是多大

画图后,可以发现,用容斥定理很简单,area = 两个大圆的相交面积 - 2 * 大圆和小圆相交面积 + 两个小圆相交面积

求面积要用余弦定理,然后就简单了

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define lowbit(x) (x&(-x))
#define INF 0x7f7f7f7f // 21 E
#define MEM 0x7f // memset 都变为 INF
#define MOD 4999 // 模
#define eps 1e-9 // 精度
#define MX 1000005 // 数据范围 int read() { //输入外挂
int res = , flag = ;
char ch;
if((ch = getchar()) == '-') flag = ;
else if(ch >= '' && ch <= '') res = ch - '';
while((ch = getchar()) >= '' && ch <= '') res = res * + (ch - '');
return flag ? -res : res;
}
// code... ... double area(double x1,double y1,double r1,double x2,double y2,double r2)
{
double d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(d>=(r1+r2)*(r1+r2)) return ;
if(d<=(r1-r2)*(r1-r2)) return r1<r2 ? PI*r1*r1 : PI*r2*r2;
d=sqrt(d);
double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
double s1=a1*r1*r1; //扇形s1
double s2=a2*r2*r2;
double sinx = sqrt(-cos(a1)*cos(a1));
double t = sinx * d * r1; //三角形
return s1+s2-t;
} int main()
{
int T;
cin>>T;
for (int cnt=;cnt<=T;cnt++)
{
double x1,y1,x2,y2,r1,r2;
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&x1,&y1);
scanf("%lf%lf",&x2,&y2);
double ans = area(x1,y1,r2,x2,y2,r2);
ans -= *area(x1,y1,r1,x2,y2,r2);
ans += area(x1,y1,r1,x2,y2,r1);
printf("Case #%d: %.6f\n",cnt,ans);
}
}

最新文章

  1. java类加载器-Tomcat类加载器
  2. nginx日志配置[转]
  3. FG模型
  4. js 自己创建ready多个可以依次加载
  5. 从后端到页面:如何全方位监控 Ruby 应用?
  6. Twitter实时搜索系统EarlyBird
  7. CQRS模式实现
  8. Swift の 函数式编程
  9. EM 期望最大化算法
  10. filter的两种使用方法
  11. Leetcode_204_Count Primes
  12. SharePoint 2007 列表页定制--4个默认页定制
  13. office-excel
  14. 如何用Python计算Softmax?
  15. wifidog源码分析 - wifidog原理
  16. iOS 点击返回键崩溃的未解之谜
  17. 退出vim
  18. java 写法推荐
  19. Json之语法
  20. PhpStorm (强大的PHP开发环境)2017.3.2 附注册方法

热门文章

  1. mysql行转列,单列转多行
  2. 对tensorflow 中的attention encoder-decoder模型调试分析
  3. 【MySQL】谈谈PhxSQL的设计和实现哲学
  4. mongoDB 删除某一字段、重新名字段
  5. 从零单排之玩转Python安全编程(II)
  6. ESLint检测JavaScript代码
  7. springBoot+springCloud学习笔记
  8. .Vue 文件 ES6 语法 webstorm 中的一个识别Bug
  9. apache重定向无效
  10. erlang 最大公约数