板子题。可以转一下坐标防止被卡。精度和常数实在难以平衡。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define double long double
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n;
const double PI=acos(-1.0);
double x[N],y[N],r[N];
struct data
{
double x;int op;
bool operator <(const data&a) const
{
return x<a.x;
}
}a[N<<1];
const double eps=1E-7;
double f(double k)
{
int m=0;
for (int i=1;i<=n;i++)
if (fabs(x[i]-k)<r[i])
{
double t=sqrt(r[i]*r[i]-(x[i]-k)*(x[i]-k));
a[++m].x=y[i]-t,a[m].op=1;
a[++m].x=y[i]+t,a[m].op=-1;
}
sort(a+1,a+m+1);
double ans=0,cur;int u=0;
for (int i=1;i<=m;i++)
{
if (u==0) cur=a[i].x;
u+=a[i].op;
if (u==0) ans+=a[i].x-cur;
}
return ans;
}
double simpson(double l,double r)
{
return (r-l)*(f(l)+f(r)+4*f((l+r)/2))/6;
}
double calc(double l,double r,double simp)
{
double mid=(l+r)/2,x=simpson(l,mid),y=simpson(mid,r);
if (fabs(x+y-simp)<eps) return x+y;
else return calc(l,mid,x)+calc(mid,r,y);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj2178.in","r",stdin);
freopen("bzoj2178.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();double L=2000,R=-2000;
for (int i=1;i<=n;i++)
{
x[i]=read(),y[i]=read(),r[i]=read();
double u=x[i]*sin(PI/3)+y[i]*cos(PI/3),v=x[i]*cos(PI/3)-y[i]*sin(PI/3);
x[i]=u,y[i]=v;
L=min(L,x[i]-r[i]),R=max(R,x[i]+r[i]);
}
#undef double
printf("%.3f",(double)calc(L,R,simpson(L,R)));
return 0;
}

  

BZOJ2178 圆的面积并(simpson积分)的更多相关文章

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

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

  2. [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并

    [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...

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

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

  4. BZOJ2178: 圆的面积并(格林公式)

    题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...

  5. BZOJ2178 圆的面积并 计算几何 辛普森积分

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...

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

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

  7. bzoj2178: 圆的面积并

    Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 ...

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

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

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

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

随机推荐

  1. 人人都是产品经理<2.0>

    之前有看过<人人都是产品经理1.0>,还认真的做了笔记,看完后不久,得知作者在第一版的内容基础上,升华性的出了第二版,即<人人都是产品经理2.0>.注:第一版和第二版跨度有6年 ...

  2. WebSphere下配置HTTP压缩

    WebSphere下配置HTTP压缩 背景 WebSphere本身的安装配置中并不包含HTTP压缩的模块,而是通过新增WebServer来实现的,WebSphere通过Plugin与WebServer ...

  3. 学习CSS布局 - margin: auto;

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. React-redux-saga

    新建sagas.js import { takeEvery , put} from 'redux-saga/effects' import axios from 'axios'; import { G ...

  5. Foreach循环输出索引值

    循环输邮索引值,使用for是没有任何问题: class Bh { public string[] str { get; set; } public void TestFor() { ; i < ...

  6. ubuntu 中iptables

    ubuntu中启动及关闭iptables 在ubuntu中由于不存在 /etc/init.d/iptales文件,所以无法使用service等命令来启动iptables,需要用modprobe命令. ...

  7. LNMP 1.x升级到LNMP 1.4教程及注意事项和多PHP版本使用教程

    LNMP 1.x版本基本都可以正常升级到1.4使用1.4的管理脚本和新的功能. 升级管理脚本:wget -c http://soft.vpser.net/lnmp/lnmp1.4.tar.gz &am ...

  8. 磁盘挂载问题:Fdisk最大只能创建2T分区的盘,超过2T使用parted

    需求说明:云服务器上买了一块8T的磁盘,准备挂载到服务器上的/data目录下. ===================================parted命令说明=============== ...

  9. Uniform Generator HDU1014

    题意 给你公式seed(x+1) = [seed(x) + STEP] % MOD ,输入step和mod, 问你是否可以从第一项0,算到mod,它们是否都不同 是 good choice 否则 ba ...

  10. 12.18 Daily Scrum

    最近大家确实都很忙,所以所有功能的实现要等到下周.   Today's Task Tomorrow's Task 丁辛 实现和菜谱相关的餐厅列表. 实现和菜谱相关的餐厅列表.             ...