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 * 大圆和小圆相交面积 + 两个小圆相交面积

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

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <map>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <vector>
  12. using namespace std;
  13. #define LL long long
  14. #define PI acos(-1.0)
  15. #define lowbit(x) (x&(-x))
  16. #define INF 0x7f7f7f7f // 21 E
  17. #define MEM 0x7f // memset 都变为 INF
  18. #define MOD 4999 // 模
  19. #define eps 1e-9 // 精度
  20. #define MX 1000005 // 数据范围
  21.  
  22. int read() { //输入外挂
  23. int res = , flag = ;
  24. char ch;
  25. if((ch = getchar()) == '-') flag = ;
  26. else if(ch >= '' && ch <= '') res = ch - '';
  27. while((ch = getchar()) >= '' && ch <= '') res = res * + (ch - '');
  28. return flag ? -res : res;
  29. }
  30. // code... ...
  31.  
  32. double area(double x1,double y1,double r1,double x2,double y2,double r2)
  33. {
  34. double d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
  35. if(d>=(r1+r2)*(r1+r2)) return ;
  36. if(d<=(r1-r2)*(r1-r2)) return r1<r2 ? PI*r1*r1 : PI*r2*r2;
  37. d=sqrt(d);
  38. double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
  39. double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
  40. double s1=a1*r1*r1; //扇形s1
  41. double s2=a2*r2*r2;
  42. double sinx = sqrt(-cos(a1)*cos(a1));
  43. double t = sinx * d * r1; //三角形
  44. return s1+s2-t;
  45. }
  46.  
  47. int main()
  48. {
  49. int T;
  50. cin>>T;
  51. for (int cnt=;cnt<=T;cnt++)
  52. {
  53. double x1,y1,x2,y2,r1,r2;
  54. scanf("%lf%lf",&r1,&r2);
  55. scanf("%lf%lf",&x1,&y1);
  56. scanf("%lf%lf",&x2,&y2);
  57. double ans = area(x1,y1,r2,x2,y2,r2);
  58. ans -= *area(x1,y1,r1,x2,y2,r2);
  59. ans += area(x1,y1,r1,x2,y2,r1);
  60. printf("Case #%d: %.6f\n",cnt,ans);
  61. }
  62. }

Intersection(计算几何)的更多相关文章

  1. POJ 1410 Intersection (计算几何)

    题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...

  2. codeforces D. Area of Two Circles' Intersection 计算几何

    D. Area of Two Circles' Intersection time limit per test 2 seconds memory limit per test 256 megabyt ...

  3. hdu-5120 Intersection(计算几何)

    题目链接: Intersection Time Limit: 4000/4000 MS (Java/Others)     Memory Limit: 512000/512000 K (Java/Ot ...

  4. POJ1410 Intersection 计算几何

    题目大意:给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交).这题蒸鹅心-- 题目思路:判断所有情况:线段是否在矩形内,线段内一点是否在矩形内,线段是 ...

  5. 计算几何(容斥原理,圆交):HDU 5120 Intersection

    Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...

  6. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

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

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

  8. POJ 1410 Intersection(计算几何)

    题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和 ...

  9. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...

随机推荐

  1. Ubuntu16.04下安装googlechrome flash 插件和安装网易云音乐

    一.ubuntu 16.04 下安装完后发现 flash无法播放没有安装flash插件因为 Adobe Flash 不再支持 linux Google 便开发了PepperFlashPlayer来替代 ...

  2. C++ 如何得到当前进程所占用的内存呢?【转】

    使用SDK的PSAPI (Process Status Helper)中的BOOL GetProcessMemoryInfo( HANDLE Process, PPROCESS_MEMORY_COUN ...

  3. depth linear

    float ConvertDepth( float depthFromTex, float4 cameraParams ){ const float near = cameraParams.z; co ...

  4. JPEG编码(二)

    来自CSDN评论区http://bbs.csdn.net/topics/190980 1. 色彩模型 JPEG 的图片使用的是 YCrCb 颜色模型, 而不是计算机上最常用的 RGB. 关于色彩模型, ...

  5. 2017.7.31 ELK+logback+redis的使用

    参考来自:spring mvc+ELK从头开始搭建日志平台 0 前提 ELK安装成功 redis安装成功 使用logback的项目运行成功 1 配置文件 1.1 pom.xml 为了使用logback ...

  6. 联想Y430P CentOS 7.3 无线网络的配置

    # uname -a # 查看内核/操作系统/CPU信息的Linux系统信息命令 [root@www ~]# uname -a Linux www SMP Tue Nov :: UTC x86_64 ...

  7. [Tips + Javascript] Make a unique array

    To make an array uniqued, we can use Set() from Javascript. const ary = ["a", "b" ...

  8. 从头认识Spring-1.7 如何通过属性注入Bean?(1)-如何通过属性向对象注入值?

    这一章节我们来讨论一下如何通过属性注入Bean? 这一章节分为两部分,第一部分我们通过属性向对象注入值,第二部分我们通过属性向对象注入还有一个对象的引用. 1.如何通过属性向对象注入值? (1)dom ...

  9. WAMP设置

    当安装好WAMP后,windows右下角会出现WAMP Server的图标,如图所示! 当中集成了PHP开发的常用功能. Localhost:表示启动浏览器打开本地首页 My Projects:项目文 ...

  10. spring aop中的propagation(传播属性)的7种配置的意思

      1.前言. 在声明式的事务处理中,要配置一个切面,即一组方法,如 <tx:advice id="txAdvice" transaction-manager="t ...