SPOJ CIRU The area of the union of circles
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的更多相关文章
- 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 ...
- SPOJ CIRU The area of the union of circles (计算几何)
题意:求 m 个圆的并的面积. 析:就是一个板子题,还有要注意圆的半径为0的情况. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...
- SPOJ CIRU The area of the union of circles ——Simpson积分
[题目分析] 圆的面积并. 直接Simpson积分,(但是有计算几何的解法,留着flag). simpson积分,如果圆出现了不连续的情况,是很容易出事情的.(脑补一下) 但是没有什么办法,本来就是一 ...
- 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]
[题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...
- 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 ! ...
- SPOJ 8073 The area of the union of circles (圆并入门)
Sphere Online Judge (SPOJ) - Problem CIRU [求圆并的若干种算法,圆并扩展算法]_AekdyCoin的空间_百度空间 参考AekdyCoin的圆并算法解释,根据 ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- SPOJ CIRU SPOJ VCIRCLE 圆的面积并问题
SPOJ VCIRCLE SPOJ CIRU 两道题都是给出若干圆 就面积并,数据规模和精度要求不同. 求圆面积并有两种常见的方法,一种是Simpson积分,另一种是几何法. 在这里给出几何方法. P ...
- SPOJ CIRU
SPOJ CIRU 题意 给出n个圆,求他们覆盖的面积. 解法 自适应Simpson,但需要将圆离散化一下,以保证我们查询的是一个连续的有圆的区间. 奇怪的是我没有离散化,样例都没有过,却把题给A了 ...
随机推荐
- javaweb基础(22)_Servlet+JSP+JavaBean实战登陆
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- 【模拟】HHHOJ#251. 「NOIP模拟赛 伍」高精度
积累模拟经验 题目描述 维护一个二进制数,支持如下操作 "+" 该数加 11 "-" 该数减 11 "*" 该数乘 22 "\&q ...
- python元组的相对不可变性
元组与多数python集合(列表.字典.集,等等)一样,保存的是对象的引用.如果引用的元素是可变的,即便元组本身不可变,但是元素依然可变.也就是说元组的不可变性其实是指tuple数据结构的物理内容(即 ...
- redis学习笔记(2)
redis学习笔记第二部分 --配置文件介绍 二,解析redis的配置文件redis.conf常见配置参数说明redis.conf 配置项说明如下:1. Redis默认不是以守护进程的方式运行,可以通 ...
- sphinx增量索引使用
sphinx在使用过程中如果表的数据量很大,新增加的内容在sphinx索引没有重建之前都是搜索不到的. 这时可以通过建立sphinx增量索引,通过定时更新增量索引,合并主索引的方式,来实现伪实时更新. ...
- 模拟发送http请求的工具推荐
做网站开发时,经常需要发送请求来测试自己的代码是否OK,这时候模拟发送http请求的工具就起到了很大的作用.特别是需要在请求带header时就更加的有必要使用工具.下面推荐的工具有的是基于系统开发的程 ...
- 如何用纯 CSS 创作一根闪电连接线
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/RBjdzZ 可交互视频 ...
- php使用curl访问https返回无结果的问题
最近在做一个微信自动登录,发起验证以后回调页面获取openid时 curl函数返回空. $appid = "appid appid "; $secret = "secre ...
- VNC远程登录端使用经验之一
1.vnc/xmanager都是经常用的远程登录软件.vnc有个缺点就是他的进程不会自动退出比如如果开了PID1再去开PID2...PIDn.那么前面的PIDn-1个进程就会一直运行如果不手动kill ...
- 《linux设备驱动开发详解》笔记——14 linux网络设备驱动
14.1 网络设备驱动结构 网络协议接口层:硬件无关,标准收发函数dev_queue_xmit()和netif_rx(); 注意,netif_rx是将接收到的数据给上层,有时也在驱动收到数据以后调用 ...