BZOJ2178:圆的面积并——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2178
给出N个圆,求其面积并。
simpson,将圆劈成两半,假设上面的叫上壳,下面的叫下壳,对这两个壳分别做一遍simpson,相减就是答案。
当然优化时间可以去掉完全包含的圆。
以及相减的时候注意同一坐标的不同解,我们要求他的并。
另外精度死活调不对,参考了:https://www.cnblogs.com/SfailSth/p/6360277.html的代码才过orz
#include<cmath>
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef double dl;
const int N=;
const dl eps=1e-;
const dl INF=;
inline int read(){
int X=,w=;char ch=;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
struct cir{
int x,y,r;
}p[N];
int n,tag[N];
struct node{
dl l,r;
}q[N];
inline bool cmp1(node a,node b){
return a.l<b.l||(a.l==b.l&&a.r<b.r);
}
inline bool cmp2(cir a,cir b){
return a.r<b.r;
}
inline dl f(dl x){
int cnt=;
for(int i=;i<=n;i++){
if(fabs(p[i].x-x)-p[i].r<-eps){
dl t=sqrt(p[i].r*p[i].r-(x-p[i].x)*(x-p[i].x));
q[++cnt].l=p[i].y-t;
q[cnt].r=p[i].y+t;
}
}
sort(q+,q+cnt+,cmp1);
dl h=-INF,ans=;
for(int i=;i<=cnt;i++){
if(h<q[i].l)ans+=q[i].r-q[i].l,h=q[i].r;
else if(h<q[i].r)ans+=q[i].r-h,h=q[i].r;
}
return ans;
}
inline dl simpson(dl l,dl r){
dl mid=(l+r)/;
return (f(l)+*f(mid)+f(r))*(r-l)/;
}
inline dl asr(dl l,dl r,dl ans){
dl mid=(l+r)/;
dl l1=simpson(l,mid),r1=simpson(mid,r);
if(fabs(l1+r1-ans)<eps)return l1+r1;
return asr(l,mid,l1)+asr(mid,r,r1);
}
int main(){
n=read();
for(int i=;i<=n;i++){
p[i].x=read(),p[i].y=read(),p[i].r=read();
}
sort(p+,p+n+,cmp2);
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
int x=p[i].x-p[j].x,y=p[i].y-p[j].y,r=p[j].r-p[i].r;
if(x*x+y*y<=r*r){
tag[i]=;break;
}
}
}
int tot=;
for(int i=;i<=n;i++)if(!tag[i])p[++tot]=p[i];
n=tot;
printf("%.3lf\n",asr(-INF,INF,simpson(-INF,INF)));
return ;
}
+++++++++++++++++++++++++++++++++++++++++++
+本文作者:luyouqi233。 +
+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/+
+++++++++++++++++++++++++++++++++++++++++++
BZOJ2178:圆的面积并——题解的更多相关文章
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- BZOJ2178: 圆的面积并(格林公式)
题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...
- BZOJ2178 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- bzoj2178: 圆的面积并
Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 ...
- BZOJ2178 圆的面积并(simpson积分)
板子题.可以转一下坐标防止被卡.精度和常数实在难以平衡. #include<iostream> #include<cstdio> #include<cmath> # ...
- 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]
[题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...
- 【BZOJ2178】圆的面积并(辛普森积分)
[BZOJ2178]圆的面积并(辛普森积分) 题面 BZOJ 权限题 题解 把\(f(x)\)设为\(x\)和所有圆交的线段的并的和. 然后直接上自适应辛普森积分. 我精度死活一个点过不去,不要在意我 ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- JAVA求圆的面积
import java.text.DecimalFormat;import java.util.Scanner; public class TheAreaOfCircle { public stati ...
随机推荐
- 深入解析UUID及其应用(转载)
UUID 编辑 UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Founda ...
- libevent学习二(Working with an event loop)
Runing the loop #define EVLOOP_ONCE 0x01 #define EVLOOP_NONBLOCK 0x02 #define EV ...
- linux部署maven
1.下载安装包 https://maven.apache.org/download.cgi 2.解压,并配置环境变量 vim /etc/profile export MAVEN_HOME=maven目 ...
- Lua学习笔记(1): HelloWorld和数据类型
Lua是一个轻量级的脚本语言,由c语言编写,容易嵌入到应用中,深受游戏开发者的青睐 环境安装 选用SciTE作为lua的IDE 可以在github找到这个开源的软件 SciTE下载链接 安装好之后打开 ...
- PHP正则相关
描述字符串排列模式的一种自定义语法规则 如果可以使用字符串函数处理的任务 就不要使用正则 正则表达式 就是通过构建具有特定规则的模式,与输入的字符信息比较 在进行 分割 匹配 查找 替换 等工作 ...
- 【模板】DFS
int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; void dfs()//参数用来表示状态 { if (到达终点状态) { ...//根据题意来添加 ...
- Python3 标准库:calendar,time
1.calendar import calendar print(calendar.month(2008,8)) #某个月 print(calendar.calendar(2008)) #某年 pri ...
- 3.配置HDFS HA
安装zookeeper下载zookeeper编辑zookeeper配置文件创建myid文件启动zookeeper配置HDFS HA配置手动HA配置自动HA启动HDFS HA namenode负责管理整 ...
- HADOOP docker(六):hive简易使用指南
前言1.hive简介1.1 hive组件与相应功能:1.2 hive的表类型1.3 分区表1.3 分隔符1.4 hive的数据存储2.数据类型2.1 基本数据类型2.1 复杂数据类型2.3 NULL3 ...
- codeforces 319B Psychos in a Line(模拟)
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At eac ...