You are given N circles and expected to calculate the area of the union of the circles !

Input

The first line is one integer n indicates the number of the circles. (1 <= n <= 1000)

Then follows n lines every line has three integers

Xi Yi Ri

indicates the coordinate of the center of the circle, and the radius. (|Xi|. |Yi|  <= 1000, Ri <= 1000)

Note that in this problem Ri may be 0 and it just means one point !

Output

The total area that these N circles with 3 digits after decimal point

Example

  1. Input:
    3
  1. 0 0 1
    0 0 1
    100 100 1
  2.  
  3. Output:
    6.283

simpson自适应积分法

精度只需要1e-6,十分友好

调试语句懒得删

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. const double eps=1e-;
  8. const int INF=1e9;
  9. const int mxn=;
  10. int read(){
  11. int x=,f=;char ch=getchar();
  12. while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
  13. while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
  14. return x*f;
  15. }
  16. //
  17. struct cir{
  18. double x,y,r;
  19. friend bool operator < (const cir a,const cir b){return a.r<b.r;}
  20. }c[mxn];int cnt=;
  21. inline double dist(cir a,cir b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
  22. //圆
  23. struct line{
  24. double l,r;
  25. friend bool operator <(const line a,const line b){return a.l<b.l;}
  26. }a[mxn],b[mxn];int lct=;
  27. double f(double x){
  28. int i,j;
  29. lct=;
  30. for(i=;i<=cnt;i++){//计算直线截得圆弧长度
  31. if(fabs(c[i].x-x)>=c[i].r)continue;
  32. double h= sqrt(c[i].r*c[i].r-(c[i].x-x)*(c[i].x-x));
  33. a[++lct].l=c[i].y-h;
  34. a[lct].r=c[i].y+h;
  35. }
  36. if(!lct)return ;
  37. double len=,last=-INF;
  38. sort(a+,a+lct+);
  39. for(i=;i<=lct;i++){//线段长度并
  40. if(a[i].l>last){len+=a[i].r-a[i].l;last=a[i].r;}
  41. else if(a[i].r>last){len+=a[i].r-last;last=a[i].r;}
  42. }
  43. // printf("x:%.3f len:%.3f\n",x,len);
  44. return len;
  45. }
  46. inline double sim(double l,double r){
  47. return (f(l)+*f((l+r)/)+f(r))*(r-l)/;
  48. }
  49. double solve(double l,double r,double S){
  50. double mid=(l+r)/;
  51. double ls=sim(l,mid);
  52. double rs=sim(mid,r);
  53. if(fabs(rs+ls-S)<eps)return ls+rs;
  54. return solve(l,mid,ls)+solve(mid,r,rs);
  55. }
  56. int n;
  57. double ans=;
  58. bool del[mxn];
  59. int main(){
  60. n=read();
  61. int i,j;
  62. double L=INF,R=-INF;
  63. for(i=;i<=n;i++){
  64. c[i].x=read(); c[i].y=read(); c[i].r=read();
  65. // L=min(L,c[i].x-c[i].r);
  66. // R=max(R,c[i].x+c[i].r);
  67. }
  68. //
  69. sort(c+,c+n+);
  70. for(i=;i<n;i++)
  71. for(j=i+;j<=n;j++){
  72. // printf("%d %.3f %.3f %.3f %.3f\n",j,c[j].x,c[i].r,c[j].r,dist(c[i],c[j]));
  73. if(c[j].r-c[i].r>=dist(c[i],c[j]))
  74. {del[i]=;break;}
  75. }
  76. for(i=;i<=n;i++)
  77. if(!del[i])c[++cnt]=c[i];
  78. //删去被包含的圆
  79. // printf("cnt:%d\n",cnt);
  80. double tmp=-INF;int blct=;
  81. for(i=;i<=cnt;i++){
  82. b[++blct].l=c[i].x-c[i].r;
  83. b[blct].r=c[i].x+c[i].r;
  84. }
  85. sort(b+,b+blct+);
  86. // printf("lct:%d\n",blct);
  87. // int tlct=t;
  88. for(i=;i<=blct;i++){
  89. // printf("%.3f %.3f\n",b[i].l,b[i].r);
  90. // printf("tmp:%.3f\n",tmp);
  91. if(b[i].r<=tmp)continue;
  92. L=max(tmp,b[i].l);
  93. // printf("%d: %.3f %.3f\n",i,L,a[i].r);
  94. ans+=solve(L,b[i].r,sim(L,b[i].r));
  95. // printf("ANS:%.3f\n",ans);
  96. // printf("nlct:%d\n",lct);
  97. tmp=b[i].r;
  98. }
  99.  
  100. // ans=solve(L,R,f((L+R)/2));
  101. printf("%.3f\n",ans);
  102. return ;
  103. }

SPOJ CIRU The area of the union of circles的更多相关文章

  1. SPOJ CIRU - The area of the union of circles (圆的面积并)

    CIRU - The area of the union of circles no tags  You are given N circles and expected to calculate t ...

  2. SPOJ CIRU The area of the union of circles (计算几何)

    题意:求 m 个圆的并的面积. 析:就是一个板子题,还有要注意圆的半径为0的情况. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...

  3. SPOJ CIRU The area of the union of circles ——Simpson积分

    [题目分析] 圆的面积并. 直接Simpson积分,(但是有计算几何的解法,留着flag). simpson积分,如果圆出现了不连续的情况,是很容易出事情的.(脑补一下) 但是没有什么办法,本来就是一 ...

  4. 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]

    [题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...

  5. SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)

    Description You are given N circles and expected to calculate the area of the union of the circles ! ...

  6. SPOJ 8073 The area of the union of circles (圆并入门)

    Sphere Online Judge (SPOJ) - Problem CIRU [求圆并的若干种算法,圆并扩展算法]_AekdyCoin的空间_百度空间 参考AekdyCoin的圆并算法解释,根据 ...

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

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

  8. SPOJ CIRU SPOJ VCIRCLE 圆的面积并问题

    SPOJ VCIRCLE SPOJ CIRU 两道题都是给出若干圆 就面积并,数据规模和精度要求不同. 求圆面积并有两种常见的方法,一种是Simpson积分,另一种是几何法. 在这里给出几何方法. P ...

  9. SPOJ CIRU

    SPOJ CIRU 题意 给出n个圆,求他们覆盖的面积. 解法 自适应Simpson,但需要将圆离散化一下,以保证我们查询的是一个连续的有圆的区间. 奇怪的是我没有离散化,样例都没有过,却把题给A了 ...

随机推荐

  1. Java基础面试操作题:线程同步代码块 两个客户往一个银行存钱,每人存三十次一次存一百。 模拟银行存钱功能,时时银行现金数。

    package com.swift; public class Bank_Customer_Test { public static void main(String[] args) { /* * 两 ...

  2. 使用filter函数筛选出素数

    function getPrimeNumber(arr) { return arr.filter(function (number) { if (typeof number !== 'number' ...

  3. Tarjan算法 详解+心得

    Tarjan算法是由Robert Tarjan(罗伯特·塔扬,不知有几位大神读对过这个名字) 发明的求有向图中强连通分量的算法. 预备知识:有向图,强连通. 有向图:由有向边的构成的图.需要注意的是这 ...

  4. ccf 201803-4 棋局评估(Python实现)

    一.原题 问题描述 试题编号: 201803-4 试题名称: 棋局评估 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很 ...

  5. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(三段式)

    Three always block style with registered outputs(Good style)

  6. Yii2 AR模型搜索数据条数不对,AR模型默认去重

    最近在做Yii2的项目时, 发现了一个yii2 自带的Ar模型会自动对搜索出来的字段去重. 默认去重字段: id,  其他字段暂没发现 1. 例如: public function fields { ...

  7. proc_info_list

    内核中每种处理器架构抽象为一个proc_info_list结构体,在arch/arm/include/asm/procinfo.h中定义, struct proc_info_list { unsign ...

  8. 水题:51Nod1095-Anigram单词

    1095 Anigram单词 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 Description 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那 ...

  9. zookeeper安装、配置、使用

    [安装] wget http://www.apache.org/dist/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar zxvf zooke ...

  10. vagrant中的precise64使用静态的能和host所在局域网的其他机器互相通信

    vagrant中的precise64使用静态的能和host所在局域网的其他机器互相通信