题目链接:

POJ:http://poj.org/problem?

id=2546

ZOJ:

problemId=597" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597

Description

Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.

Input

In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.

Output

The output file must contain single real number - the area.

Sample Input

  1. 20.0 30.0 15.0 40.0 30.0 30.0

Sample Output

  1. 608.366

Source

Northeastern Europe 2000, Far-Eastern Subregion

题意:

求两圆相交的面积!

直接上模板

代码例如以下:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <iostream>
  5. #include <algorithm>
  6. //#include <complex>
  7. //#include <iomanip>
  8. using namespace std;
  9. const double eps = 1e-8;
  10. const double PI = acos(-1.0);
  11.  
  12. int sgn(double x)
  13. {
  14. if(fabs(x) < eps) return 0;
  15. if(x < 0) return - 1;
  16. else return 1;
  17. }
  18. struct Point
  19. {
  20. double x, y;
  21. Point(){}
  22. Point(double _x, double _y)
  23. {
  24. x = _x; y = _y;
  25. }
  26. Point operator -( const Point &b) const
  27. {
  28. return Point(x - b. x, y - b. y);
  29. }
  30. //叉积
  31. double operator ^ (const Point &b) const
  32. {
  33. return x*b. y - y*b. x;
  34. }
  35. //点积
  36. double operator * (const Point &b) const
  37. {
  38. return x*b. x + y*b. y;
  39. }
  40. //绕原点旋转角度B(弧度值),后x,y的变化
  41. void transXY(double B)
  42. {
  43. double tx = x,ty = y;
  44. x = tx* cos(B) - ty*sin(B);
  45. y = tx* sin(B) + ty*cos(B);
  46. }
  47. };
  48. //*两点间距离
  49. double dist( Point a, Point b)
  50. {
  51. return sqrt((a-b)*(a- b));
  52. }
  53. //两个圆的公共部分面积
  54. double Area_of_overlap(Point c1, double r1, Point c2, double r2)
  55. {
  56. double d = dist(c1,c2);
  57. if(r1 + r2 < d + eps) return 0;
  58. if(d < fabs(r1 - r2) + eps)
  59. {
  60. double r = min(r1,r2);
  61. return PI*r*r;
  62. }
  63. double x = (d*d + r1*r1 - r2*r2)/(2*d);
  64. double t1 = acos(x / r1);
  65. double t2 = acos((d - x)/r2);
  66. return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
  67. }
  68.  
  69. int main()
  70. {
  71. double x1, y1, r1, x2, y2, r2;
  72. while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
  73. {
  74. Point c1, c2;
  75. c1.x = x1;
  76. c1.y = y1;
  77. c2.x = x2;
  78. c2.y = y2;
  79. double ans = Area_of_overlap(c1,r1,c2,r2);
  80. printf("%.3lf\n",ans);
  81. //cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
  82. }
  83. return 0;
  84. }

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)的更多相关文章

  1. 求两圆相交部分面积(C++)

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

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

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

  3. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. poj2546Circular Area(两圆相交面积)

    链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...

  5. POJ 2546 Circular Area(两个圆相交的面积)

    题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...

  6. 两圆相交求面积 hdu5120

    转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...

  7. [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点

    POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...

  8. ZOJ 1280 Interesting Lines | 求两直线交点

    原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...

  9. UVa 10674 (求两圆公切线) Tangents

    题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...

随机推荐

  1. yum安装失败:ublic key for **.rpm is not installed

    yum install mysql-server --nogpgcheck package_need_to_install

  2. Apache+Tomcat+mod_jk实现负载均衡

    最近公司提出了负载均衡的新需求,以减轻网站的高峰期的服务器负担.趁空闲时间我就准备了一下这方面的知识,都说有备无患嘛.网上相关资料很多,但是太散.我希望可以通过这篇随笔,系统的总结. 一.Tomcat ...

  3. [Android]使用 Eclipse 给 APK 签名时遇到的两个问题及解决办法

    问题 今天用 APK 反编译工具看了一下自己项目生成的 APK 文件,发现代码并没有混淆,于是设置了用 ProGuard 混淆代码,可是混淆是必须在非 Debug 模式才会生效的,即使你是以 Rele ...

  4. Angularjs里面跨作用域的实战!

    好久没有来写博客了,最近一直在用Google的AngularJS,后面我自己简称AngularJS就叫AJ吧! 学习AngularJS一路也是深坑颇多啊--!就不多说了,不过还是建议大家有时间去学下下 ...

  5. docker stack 部署nginx

    =============================================== 2018/7/29_第1次修改                       ccb_warlock == ...

  6. ajax发送多个跨域请求回调不混乱

    var count = 0; var codes = ""; function refreshCache(urls){ try { var url = urls.split(&qu ...

  7. js防止sql注入的参数过滤

    js防止sql注入的参数过滤 <script language="javascript"> <!-- var url = location.search; var ...

  8. php生成随机数

    生成1-10之间的随机数,不重复. 方法一:用shuffle函数. <?php $arr=range(1,10); shuffle($arr); foreach($arr as $values) ...

  9. 【LOJ】#2110. 「JLOI2015」管道连接

    题解 我们先跑一个斯坦纳树出来 斯坦纳树是什么,是一个包含点集里的点联通所需要的最小的价值,显然他们联通的方式必然是一棵树 我们可以设一个状态为\(dis[i][S]\)表示以第i个点为根,点集为\( ...

  10. redis 相关知识点

    (1)什么是redis? Redis 是一个基于内存的高性能key-value数据库. (有空再补充,有理解错误或不足欢迎指正) (2)Reids的特点 Redis本质上是一个Key-Value类型的 ...