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

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

simpson自适应积分法

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

调试语句懒得删

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const double eps=1e-;
const int INF=1e9;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
//
struct cir{
double x,y,r;
friend bool operator < (const cir a,const cir b){return a.r<b.r;}
}c[mxn];int cnt=;
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));}
//圆
struct line{
double l,r;
friend bool operator <(const line a,const line b){return a.l<b.l;}
}a[mxn],b[mxn];int lct=;
double f(double x){
int i,j;
lct=;
for(i=;i<=cnt;i++){//计算直线截得圆弧长度
if(fabs(c[i].x-x)>=c[i].r)continue;
double h= sqrt(c[i].r*c[i].r-(c[i].x-x)*(c[i].x-x));
a[++lct].l=c[i].y-h;
a[lct].r=c[i].y+h;
}
if(!lct)return ;
double len=,last=-INF;
sort(a+,a+lct+);
for(i=;i<=lct;i++){//线段长度并
if(a[i].l>last){len+=a[i].r-a[i].l;last=a[i].r;}
else if(a[i].r>last){len+=a[i].r-last;last=a[i].r;}
}
// printf("x:%.3f len:%.3f\n",x,len);
return len;
}
inline double sim(double l,double r){
return (f(l)+*f((l+r)/)+f(r))*(r-l)/;
}
double solve(double l,double r,double S){
double mid=(l+r)/;
double ls=sim(l,mid);
double rs=sim(mid,r);
if(fabs(rs+ls-S)<eps)return ls+rs;
return solve(l,mid,ls)+solve(mid,r,rs);
}
int n;
double ans=;
bool del[mxn];
int main(){
n=read();
int i,j;
double L=INF,R=-INF;
for(i=;i<=n;i++){
c[i].x=read(); c[i].y=read(); c[i].r=read();
// L=min(L,c[i].x-c[i].r);
// R=max(R,c[i].x+c[i].r);
}
//
sort(c+,c+n+);
for(i=;i<n;i++)
for(j=i+;j<=n;j++){
// printf("%d %.3f %.3f %.3f %.3f\n",j,c[j].x,c[i].r,c[j].r,dist(c[i],c[j]));
if(c[j].r-c[i].r>=dist(c[i],c[j]))
{del[i]=;break;}
}
for(i=;i<=n;i++)
if(!del[i])c[++cnt]=c[i];
//删去被包含的圆
// printf("cnt:%d\n",cnt);
double tmp=-INF;int blct=;
for(i=;i<=cnt;i++){
b[++blct].l=c[i].x-c[i].r;
b[blct].r=c[i].x+c[i].r;
}
sort(b+,b+blct+);
// printf("lct:%d\n",blct);
// int tlct=t;
for(i=;i<=blct;i++){
// printf("%.3f %.3f\n",b[i].l,b[i].r);
// printf("tmp:%.3f\n",tmp);
if(b[i].r<=tmp)continue;
L=max(tmp,b[i].l);
// printf("%d: %.3f %.3f\n",i,L,a[i].r);
ans+=solve(L,b[i].r,sim(L,b[i].r));
// printf("ANS:%.3f\n",ans);
// printf("nlct:%d\n",lct);
tmp=b[i].r;
} // ans=solve(L,R,f((L+R)/2));
printf("%.3f\n",ans);
return ;
}

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. Word2vec资料

    Word2vec 很好的资料 Word2Vec-知其然知其所以然   https://www.zybuluo.com/Dounm/note/591752 Word2Vec数学原理讲解 http://w ...

  2. Java中this关键字的用法

    this关键字作用: 1. 如果存在同名成员变量与局部变量时,在方法内部默认是访问局部变量的数据,可以通过this关键字指定访问成员变量的数据. 2. 在一个构造函数中可以调用另外一个构造函数初始化对 ...

  3. Bootstrap历练实例:默认的媒体对象

    Bootstrap 多媒体对象(Media Object) 本章我们将讲解 Bootstrap 中的多媒体对象(Media Object).这些抽象的对象样式用于创建各种类型的组件(比如:博客评论), ...

  4. Js笔记 14

      <script> // <!-- 课 对象   // //对象的创建方法 // 1.var obj = {} plainobject 对象字面量 对象直接量 // 2.构造函数 ...

  5. Linux curl 详解

    Linux下载工具Curl也是Linux下不错的命令行下载工具,小巧.高速,唯一的缺点是不支持多线程下载.以下是他的安装和功能. 安装 $ tar zxvf curl-7.14.0.tar.gz $ ...

  6. cocos2dx 3.x c++代码打包给lua调用过程(mac)

    下载cocos2dx 框架,在应用程序->cocos->framework->cocos2d-x-3.x->tools->tolua目录下,一个ini文件对应一个py文件 ...

  7. HDU-4848-Such Conquering

    这题就是深搜加剪枝,有一个很明显的剪枝,因为题目中给出了一个deadline,所以我们一定要用这个deadline来进行剪枝. 题目的意思是求到达每个点的时间总和,当时把题看错了,卡了好久. 剪枝一: ...

  8. 【主席树 启发式合并】bzoj3123: [Sdoi2013]森林

    小细节磕磕碰碰浪费了半个多小时的时间 Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M ...

  9. nginx下配置laravel+rewrite重写

    server { listen ; server_name ha.d51v.cn; #access_log /data/wwwlogs/access_nginx.log combined; root ...

  10. PHP 日常开发过程中的bug集合(持续更新中。。。)

    PHP 日常开发过程中的bug集合(持续更新中...) 在日常php开发过程中,会遇到一些意想不到的bug,所以想着把这些bug记录下来,以免再犯! 1.字符串 '0.00'.'0.0'.'0'  是 ...