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
 
两个圆环相交,然而我只有圆相交的板子
首先拿其中一个大圆A与另一个大圆B和小圆b算交面积,两者相减,求的是A与圆环Bb相交的面积 area1
然后拿小圆a另一个大圆B和小圆b算交面积,两者相减,求的是a与圆环Bb相交的面积,area2
我们输出area1-area2就行了
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const double PI = acos(-1.0);
  5. const double eps = 1e-;
  6. int dblcmp (double k)
  7. {
  8. if (fabs(k)<eps) return ;
  9. return k>?:-;
  10. }
  11. struct Point
  12. {
  13. double x,y;
  14. };
  15. double dis (Point a,Point b)
  16. {
  17. return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  18. }
  19. double area_of_overlap (Point c1,double r1,Point c2,double r2)//圆相交模板
  20. {
  21. double d = dis(c1,c2);
  22. if (r1+r2<d+eps) return ;
  23. if (d<fabs(r1-r2)+eps){
  24. double r = min(r1,r2);
  25. return PI*r*r;
  26. }
  27. double x = (d*d+r1*r1-r2*r2)/(*d);
  28. double t1 = acos(x/r1);
  29. double t2 = acos((d-x)/r2);
  30. return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
  31. }
  32. int t;
  33. int casee = ;
  34. int main()
  35. {
  36. //freopen("de.txt","r",stdin);
  37. scanf("%d",&t);
  38. while (t--){
  39. Point p1,p2;
  40. double r1,r2;
  41. scanf("%lf%lf",&r1,&r2);
  42. scanf("%lf%lf",&p1.x,&p1.y);
  43. scanf("%lf%lf",&p2.x,&p2.y);
  44. if (dblcmp(r1-r2)>) swap(r1,r2);
  45. double ans = area_of_overlap (p1,r2,p2,r2) -area_of_overlap (p1,r2,p2,r1)
  46. -(area_of_overlap (p1,r1,p2,r2) - area_of_overlap(p1,r1,p2,r1) );
  47. /*double ans = area (p1,r2,p2,r2) -area (p1,r2,p2,r1)
  48. -(area(p1,r1,p2,r2) - area(p1,r1,p2,r1) );*/
  49. printf("Case #%d: %.6f\n",++casee,ans);
  50. }
  51. return ;
  52. }
 

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

  1. hdu 5120 Intersection 圆环面积交

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

  2. hdoj 5120 Intersection 圆环面积求交

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

  3. hdu 5120(2014北京—求圆相交)

    题意:求环的相交面积 思路: 通过画图可知,面积= 大圆相交面积 - 大小圆相交面积*2 + 小小圆相交面积  再通过圆相交模板计算即可 #include <iostream> #incl ...

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

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

  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 两个圆的面积交

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

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

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

  8. HDU 5120 Intersection(几何模板题)

    题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...

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

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

随机推荐

  1. Linux学习篇(三)-Linux操作系统及常用命令

    小知识:南桥北桥 北桥是高速总线控制器,在CPU附近,连接内存和CPU,需要传输大量数据. 南桥是低速总线控制器,用于连接IO设备(硬盘键盘鼠标等),IO设备由南桥汇总会直接传入北桥.,目前cpu可以 ...

  2. Vagrant 入门 - 项目设置

    原文地址 配置 Vagrant 项目的第一步是创建 Vagrantfile 文件.Vagrantfile 文件的目的有两个: 设置项目的根目录.Vagrant 中的许多配置选项是相对于这个根目录的. ...

  3. Vue访问子组件实例或子元素

    1 尽管存在 prop 和事件,有的时候你仍可能需要在 JavaScript 里直接访问一个子组件(例如,调用子组件的方法).为了达到这个目的,你可以通过 ref 特性为这个子组件赋予一个 ID 引用 ...

  4. C#将字符串Split()成数组

    string str="aaajbbbjccc";string[] sArray=str.Split('j');foreach(string i in sArray) Respon ...

  5. /dev/random vs /dev/urandom

    If you want random data in a Linux/Unix type OS, the standard way to do so is to use /dev/random or ...

  6. ES6——字符串

    1.多了两个方法       1)startsWith       2)endsWith 2.模板字符串(`..`)—— 方便字符串连接   `反单引号        1)可以直接把表达式塞进去 &a ...

  7. quotaon - 开启关闭文件系统配额

    总览 (SYNOPSIS) quotaon [ -e | d ] [ -vug ] filesystem... quotaon [ -e | d ] [ -avug ] quotaoff [ -e | ...

  8. Tutorial2

    一.写一个tf2的broadcaster 本教程关于怎样broadcast一个机器人的坐标系到tf2上. 1.创建一个learning_tf2包 catkin_create_pkg learning_ ...

  9. DFSORT

    1.1   Outline   I.             Introduction Overview 2.1    What is DFSORT? 2.2    Usage of DFSORT 2 ...

  10. 2017ICPC沈阳赛现场赛 L-Tree (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 题目大意:给一棵树,需要用k种颜色给树上的节点染色,问你在最优的染色方案下,相同颜色的节点连接的 ...