直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段。

然而一定要去掉被其他圆完全覆盖的圆,否则会TLE

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-13;
const int N=1005;
int n,m;
double mn=1e13,mx=-1e13;
bool fl[N];
struct cir
{
double x,y,r;
double operator < (const cir &a) const
{
return r<a.r;
}
}c[N];
struct qwe
{
double l,r;
qwe(double L=0,double R=0)
{
l=L,r=R;
}
bool operator < (const qwe &a) const
{
return l<a.l;
}
}a[N];
int cmp(double x)
{
if(x<=eps&&x>=-eps)
return 0;
return x>0?1:-1;
}
double f(double x)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
double dis=fabs(c[i].x-x);
if(cmp(dis-c[i].r)<0)
{
double len=sqrt(c[i].r*c[i].r-dis*dis);
a[++cnt]=qwe(c[i].y-len,c[i].y+len);
}
}
if(!cnt)
return 0;
sort(a+1,a+1+cnt);
double l=a[1].l,r=a[1].r,ans=0;
for(int i=2;i<=cnt;i++)
{
if(cmp(a[i].l-r)<=0)
r=max(r,a[i].r);
else
ans+=r-l,l=a[i].l,r=a[i].r;
}
ans+=r-l;
return ans;
}
double sps(double l,double r,double now,double fl,double fr,double fm)
{
double mid=(l+r)/2,ffl=f((l+mid)/2),ffr=f((mid+r)/2),p=(fl+fm+ffl*4)*(mid-l)/6,q=(fm+fr+ffr*4)*(r-mid)/6;
if(cmp(now-p-q)==0)
return now;
else
return sps(l,mid,p,fl,fm,ffl)+sps(mid,r,q,fm,fr,ffr);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
mn=min(mn,c[i].x-c[i].r),mx=max(mx,c[i].x+c[i].r);
}//cout<<"OK"<<endl;
sort(c+1,c+1+n);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(cmp(sqrt((c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y-c[j].y)*(c[i].y-c[j].y))+c[i].r-c[j].r)<=0)
{
fl[i]=1;
break;
}
for(int i=1;i<=n;i++)
if(!fl[i])
c[++m]=c[i];
n=m;
double fl=f(mn),fr=f(mx),fm=f((mn+mx)/2);
printf("%.3lf\n",sps(mn,mx,(fl+4*fm+fr)*(mx-mn)/6,fl,fr,fm));
return 0;
}

bzoj 2178 圆的面积并【simpson积分】的更多相关文章

  1. BZOJ 2178 圆的面积并 ——Simpson积分

    [题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include < ...

  2. BZOJ 2178: 圆的面积并 [辛普森积分 区间并]

    2178: 圆的面积并 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1740  Solved: 450[Submit][Status][Discus ...

  3. bzoj 2178 圆的面积并 —— 辛普森积分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...

  4. bzoj 2178 圆的面积并——辛普森积分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...

  5. BZOJ 2178: 圆的面积并 (辛普森积分)

    code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...

  6. [BZOJ 2178] 圆的面积并 【Simpson积分】

    题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13  2)要去掉被其他圆包含的圆. ...

  7. 【BZOJ】2178: 圆的面积并

    http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...

  8. BZOJ 1845: [Cqoi2005] 三角形面积并 (辛普森积分)

    大力辛普森积分 精度什么的搞了我好久- 学到了Simpson的一个trick 深度开11,eps开1e-4.跑的比有些扫描线还快- CODE #include <bits/stdc++.h> ...

  9. BZOJ 1502 月下柠檬树(simpson积分)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1502 题意:给出如下一棵分层的树,给出每层的高度和每个面的半径.光线是平行的,与地面夹角 ...

随机推荐

  1. Object-C Xcode 编译提示 note: please rebuild precompiled header ZWYLPrefixHeader

    错误提示如下图 解决思路: 由于手欠不小心,在.pch文件上的第一行加了几个文字,删除以后,还有一个空行,估计是这个空行引起的.删除这个空行,就好了.

  2. HDU 5667 Sequence

    指数有递推式,可以通过矩阵快速幂来求解.再用下面这公式快速幂取模即可. (C是素数) #include<cstdio> #include<cstring> #include&l ...

  3. 洛谷—— P1714 切蛋糕

    https://www.luogu.org/problem/show?pid=1714 题目描述 今天是小Z的生日,同学们为他带来了一块蛋糕.这块蛋糕是一个长方体,被用不同色彩分成了N个相同的小块,每 ...

  4. Protobuf 完整解析 - 公司最常用的数据交互协议

    Google Protocol Buffer(简称 Protobuf)是一种轻便高效的结构化数据存储格式,平台无关.语言无关.可扩展,可用于通讯协议和数据存储等领域. 数据交互xml.json.pro ...

  5. CEF3研究(三)

    一.Off-Screen Rendering 脱屏绘制 CEF的脱屏渲染并不创建源生的浏览器窗口,而是CEF提供主应用程序在无效区域和像素buffer里渲染,然后主应用程序通过鼠标.键盘和焦点事件通知 ...

  6. markdown 插入latex公式练习

    markdown 插入latex公式 $$公式$$表示行间公式,本来Tex中使用\(公式\)表示行内公式,但因为Markdown中\是转义字符,所以在Markdown中输入行内公式使用\\(公式\\) ...

  7. webpack-Dependency Graph(依赖图)

    依赖图(Dependency Graph) 任何时候,一个文件依赖于另一个文件,webpack 就把此视为文件之间有依赖关系. 这使得 webpack 可以接收非代码资源(non-code asset ...

  8. Vs2012在Linux开发中的应用(5):项目属性的定义

    VS的项目属性表实际上是由一系列的XML文件定义的,都存放在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\2052文件夹下.我们全然能够 ...

  9. 使用 maskView 设计动画

    1.maskView(maskLayer) 基本原理 :可类比于多张png图片叠加遮罩 2.maskView配合CAGradientLayer,alpha通道图片的使用.maskView是iOS8以上 ...

  10. [IT学习]转载python 项目 计算器

    这个是从网上搜到的Python小项目之计算器(原文地址:http://www.2cto.com/kf/201402/279637.html).但该段代码估计是Python 2 写的. 如果你使用的程序 ...