http://www.lydsy.com/JudgeOnline/problem.php?id=2178

题意:给出n<=1000个圆,求这些圆的面积并


  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. #include <set>
  9. #include <map>
  10. #include <sstream>
  11. using namespace std;
  12. typedef long long ll;
  13. #define pb push_back
  14. #define rep(i, n) for(int i=0; i<(n); ++i)
  15. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  16. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  17. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  18. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  19. #define CC(i,a) memset(i,a,sizeof(i))
  20. #define read(a) a=getint()
  21. #define print(a) printf("%d", a)
  22. #define dbg(x) cout << (#x) << " = " << (x) << endl
  23. #define error(x) (!(x)?puts("error"):0)
  24. #define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
  25. inline int getint() { static int r, k; r=0,k=1; static char c; c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
  26.  
  27. const double eps=1e-6, PI=acos(-1);
  28. int dcmp(double x) { return abs(x)<eps?0:(x<0?-1:1); }
  29. double sqr(double x) { return x*x; }
  30. struct iP { double x, y; iP(double _x=0, double _y=0) : x(_x), y(_y) {} };
  31. double dis(iP &a, iP &b) { return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); }
  32. struct iC {
  33. iP p; double r;
  34. iP getP(double d) { return iP(p.x+cos(d)*r, p.y+sin(d)*r); }
  35. double areaH(double d) { return (d-sin(d))/2*sqr(r); }
  36. };
  37. double angle(iP &a, iP &b) {
  38. static double x, y;
  39. x=b.x-a.x; y=b.y-a.y;
  40. return atan2(y, x);
  41. }
  42. void CCi(iC &a, iC &b, double &ang1, double &ang2) {
  43. static double ang, d, R, r, da;
  44. d=dis(a.p, b.p); //dbg(d);
  45. ang=angle(a.p, b.p);
  46. R=a.r; r=b.r; //dbg((sqr(R)+sqr(d)-sqr(r))/2/R/d);
  47. da=acos((sqr(R)+sqr(d)-sqr(r))/2/R/d);
  48. ang1=ang-da;
  49. ang2=ang+da;
  50. }
  51.  
  52. const int N=1105;
  53. iC a[N];
  54. int n, cnt;
  55. bool nok[N];
  56. struct dat { double pos; int k; }b[N*5];
  57. bool cmp(const dat &a, const dat &b) { return a.pos<b.pos; }
  58.  
  59. int main() {
  60. read(n);
  61. for1(i, 1, n) scanf("%lf%lf%lf", &a[i].p.x, &a[i].p.y, &a[i].r);
  62. for1(i, 1, n) for1(j, 1, n) if(!nok[j] && i!=j) {
  63. double d=dis(a[i].p, a[j].p);
  64. if(dcmp(a[j].r-a[i].r-d)>=0) { nok[i]=1; break; }
  65. }
  66. double ang1, ang2, PI2=PI*2, ans=0;
  67. int sum=0;
  68. iP A, B;
  69. for1(i, 1, n) if(!nok[i]) {
  70. cnt=0;
  71. for1(j, 1, n) if(i!=j && !nok[j]) {
  72. if(dcmp(dis(a[i].p, a[j].p)-a[i].r-a[j].r)>=0) continue;
  73. CCi(a[i], a[j], ang1, ang2);
  74. if(dcmp(ang1)<0) ang1+=PI2;
  75. if(dcmp(ang2)<0) ang2+=PI2;
  76. if(dcmp(ang1-ang2)>0) {
  77. ++cnt; b[cnt].pos=0; b[cnt].k=1;
  78. ++cnt; b[cnt].pos=ang2; b[cnt].k=-1;
  79. ++cnt; b[cnt].pos=ang1; b[cnt].k=1;
  80. ++cnt; b[cnt].pos=PI2; b[cnt].k=-1;
  81. }
  82. else {
  83. ++cnt; b[cnt].pos=ang1; b[cnt].k=1;
  84. ++cnt; b[cnt].pos=ang2; b[cnt].k=-1;
  85. }
  86. }
  87. ++cnt; b[cnt].pos=0; b[cnt].k=0;
  88. ++cnt; b[cnt].pos=PI2; b[cnt].k=0;
  89. sort(b+1, b+1+cnt, cmp);
  90. sum=0;
  91. for1(j, 1, cnt-1) {
  92. sum+=b[j].k;
  93. if(!sum) {
  94. ans+=a[i].areaH(b[j+1].pos-b[j].pos);
  95. A=a[i].getP(b[j].pos);
  96. B=a[i].getP(b[j+1].pos);
  97. ans+=(A.x*B.y-A.y*B.x)/2;
  98. }
  99. }
  100. }
  101. printf("%.3f\n", ans);
  102. return 0;
  103. }

这题坑了我3h啊啊啊啊啊.....................................................我就一sb...

这题有多种解法,什么是辛普森积分我不知道QAQ因此这种做法是一个坑....以后再填..

首先得知道如何求这些圆的并:

圆的面积并=每个圆没有被覆盖的弧(弦那里算起)的面积和+所有相交圆被覆盖弧所组成的多边形(由弦做边)

正确性自己画图.....

因此题目变为先求没有被覆盖的弧(直接离散圆周长为线,具体操作请看上上一题...),然后算出每个圆未被覆盖(就是覆盖弧的弦以外的)的面积,然后再用叉积求出多边形面积(原理就是多边形的面积可以通过加加减减得到...)

然后就完了

好题!

【BZOJ】2178: 圆的面积并的更多相关文章

  1. BZOJ 2178: 圆的面积并 [辛普森积分 区间并]

    2178: 圆的面积并 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1740  Solved: 450[Submit][Status][Discus ...

  2. [BZOJ 2178] 圆的面积并 【Simpson积分】

    题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13  2)要去掉被其他圆包含的圆. ...

  3. bzoj 2178 圆的面积并 —— 辛普森积分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...

  4. bzoj 2178 圆的面积并——辛普森积分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...

  5. bzoj 2178 圆的面积并【simpson积分】

    直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段. 然而一定要去掉被其他圆完全覆盖的圆,否则会TLE #include<iostream> #incl ...

  6. BZOJ 2178 圆的面积并 ——Simpson积分

    [题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include < ...

  7. BZOJ 2178: 圆的面积并 (辛普森积分)

    code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...

  8. 【BZOJ】【2178】圆的面积并

    自适应辛普森积分 Orz Hzwer 辛普森真是个强大的东西……很多东西都能积= = 这题的正解看上去很鬼畜,至少我这种不会计算几何的渣渣是写不出来……(对圆的交点求图包,ans=凸包的面积+一堆弓形 ...

  9. [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并

    [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...

随机推荐

  1. 连接池 druid(阿里巴巴的框架)

      引用自:http://blog.163.com/hongwei_benbear/blog/static/1183952912013518405588/ 说的是现在最好的连接池   注: 属性跟 d ...

  2. Windows2003操作系统SQL Server 2008安装图解(详细)

    最近不少用户在windows2003 server 32位操作系统上安装SQL Server2008总是失败,出现大量错误.今天经过通过我反复测试安装,找出了一个便捷的安装方法,节省大家宝贵时间,具体 ...

  3. linux文件分割(将大的日志文件分割成小的)

    linux文件分割(将大的日志文件分割成小的) linux下文件分割可以通过split命令来实现,可以指定按行数分割和安大小分割两种模式.Linux下文件合并可以通过cat命令来实现,非常简单. 在L ...

  4. tcp粘包问题(封包)

    tcp粘包分析     http://blog.csdn.net/zhangxinrun/article/details/6721495 解决TCP网络传输“粘包”问题(经典)       http: ...

  5. xenomai安装

    一.Linux内核打实时补丁 1.将下载的Linux和xenomai安装包放在/usr/src目录下,并解压文件包,命令如下 tar xjf  Linux-3.8.13.tar.bz2   tar x ...

  6. 1.saltstack基础笔记

    环境: master: 节点node1:阿里云:121.42.195.15 centos6.6 minion: 节点node2:腾讯云:182.254.157.19 centos6.6 一.salts ...

  7. 【mysql】执行mysql脚本

    来源:http://zhidao.baidu.com/link?url=p78PlTJZlheB4uSKCkmZApg-3qrTIBCS3yI5LbGJLEAnUuO3-4GE6dLqq1LWC_kn ...

  8. mongodb数据结构学习1--增删改查

    插入文档 在数据库中,数据插入是最基本的操作,在MongoDB使用db.collection.insert(document)语句来插入文档: document是文档数据,collection是存放文 ...

  9. kindEditort图片自动上传

    参考:http://www.cnblogs.com/jaxu/p/3824583.html (赞一个)

  10. ytu 2030: 求实数绝对值(水题)

    2030: 求实数绝对值 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 10[Submit][Status][Web Board] ...