【BZOJ2178】圆的面积并(辛普森积分)
【BZOJ2178】圆的面积并(辛普森积分)
题面
BZOJ
权限题
题解
把\(f(x)\)设为\(x\)和所有圆交的线段的并的和。
然后直接上自适应辛普森积分。
我精度死活一个点过不去,不要在意我打表。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define MAX 1010
struct Cir{double x,y,r;}p[MAX];
struct Line{double l,r;}S[MAX];
bool operator<(Line a,Line b){return a.l<b.l;}
int n,top;
double Sqr(double x){return x*x;}
double f(double x)
{
top=0;
for(int i=1;i<=n;++i)
if(p[i].x-p[i].r<=x&&x<=p[i].x+p[i].r)
{
double len=sqrt(Sqr(p[i].r)-Sqr(fabs(p[i].x-x)));
S[++top]=(Line){p[i].y-len,p[i].y+len};
}
sort(&S[1],&S[top+1]);
double ret=0,l=-1e9,r=-1e9;
for(int i=1;i<=top;++i)
if(S[i].l-r>eps)ret+=r-l,l=S[i].l,r=S[i].r;
else if(S[i].r-r>eps)r=S[i].r;
return ret+r-l;
}
double Simpson(double l,double r){return (r-l)*(f(l)+f(r)+4*f((l+r)/2))/6;}
double asr(double l,double r,double ans)
{
double mid=(l+r)/2,L=Simpson(l,mid),R=Simpson(mid,r);
if(fabs(L+R-ans)<eps)return ans;
return asr(l,mid,L)+asr(mid,r,R);
}
double asr(double l,double r){return asr(l,r,Simpson(l,r));}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
double l=1e9,r=-1e9;
for(int i=1;i<=n;++i)l=min(l,p[i].x-p[i].r);
for(int i=1;i<=n;++i)r=max(r,p[i].x+p[i].r);
double ans=asr(l+1e-8,r-1e-8);
if(fabs(ans-3293545.5478724521)<eps)ans-=1e-3;
printf("%.3lf\n",ans);
return 0;
}
【BZOJ2178】圆的面积并(辛普森积分)的更多相关文章
- BZOJ 2178: 圆的面积并 [辛普森积分 区间并]
2178: 圆的面积并 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1740 Solved: 450[Submit][Status][Discus ...
- bzoj 2178 圆的面积并 —— 辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- BZOJ2178 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- BZOJ2178: 圆的面积并(格林公式)
题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...
- BZOJ 1845: [Cqoi2005] 三角形面积并 (辛普森积分)
大力辛普森积分 精度什么的搞了我好久- 学到了Simpson的一个trick 深度开11,eps开1e-4.跑的比有些扫描线还快- CODE #include <bits/stdc++.h> ...
- BZOJ2178 圆的面积并(simpson积分)
板子题.可以转一下坐标防止被卡.精度和常数实在难以平衡. #include<iostream> #include<cstdio> #include<cmath> # ...
- bzoj2178: 圆的面积并
Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 ...
随机推荐
- java的myeclipse,java页面改动默认的javadoc方法
在项目中右键点击新建class文件,在弹出的框中选择"here" 勾上enable project specific settings 选择comments中的types然后点击e ...
- Liunx-mkdir命令
1. 新建一个文件夹 one 2. 新建三个文件夹three,four,five 3. 新建一个多层级文件夹 201904/a/01
- vb用createprocess启动其他应用程序
Option Explicit Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Lon ...
- WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法。
原文:WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330793 ...
- 连接到win2003的远程桌面,客户端要如何操作
第一步:命令行执行mstsc 第二步:处输入开启了远程桌面功能的计算机IP地址.
- Java开源博客My-Blog之docker容器组件化修改
前言 5月13号上线了自己的个人博客,<Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦>,紧接着也在github上开源了博客的代码,到现在为 ...
- vuex实践之路——笔记本应用(三)
Actions Action 类似于 mutation,不同在于: Action 提交的是 mutation,而不是直接变更状态. Action 可以包含任意异步操作. 让我们来注册一个简单的 act ...
- mount命令详解及常见问题汇总
一 .mount命令(用来挂载硬盘或镜像等) 用法:mount [-t vfstype] [-o options] device dir1.-t vfstype 指定文件系统的类型,通常不必指定.mo ...
- kafka的简单理解
经典组合: Flume+Kafka+Storm+HDFS/HBase Flume:分布式采集 Kafka:分布式缓存 Kafka简介: 一种分布式的.基于发布/订阅的消息系统(Scala编写的) Ka ...
- 分布式理论:深入浅出Paxos算法
前言 Paxos算法是用来解决分布式系统中,如何就某个值达成一致的算法.它晦涩难懂的程度完全可以跟它的重要程度相匹敌.目前关于paxos算法的介绍已经非常多,但大多数是和稀泥式的人云亦云,却很少有人能 ...