【题目分析】

史上最良心样例,史上最难调样例。

Simpson积分硬上。

听说用long double 精度1e-10才能过。

但是double+1e-6居然过了。

【代码】

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> #include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 1005
#define eps 1e-6
#define db double
#define ll long long
#define ldb long double
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
} int n,cnt=0,tag[maxn],tot;
struct Circle{int x,y,r;}c[maxn];
struct Segment{db l,r;}a[maxn]; bool cmp(Segment x,Segment y)
{return x.l==y.l?x.r<y.r:x.l<y.l;} bool cmp1(Circle a,Circle b)
{return a.r<b.r;} db get(db x)
{
int cnt=0;
F(i,1,n) if (fabs(c[i].x-x)<=c[i].r-eps)
{
db tmp=sqrt(c[i].r*c[i].r-(x-c[i].x)*(x-c[i].x));
a[++cnt]=(Segment){c[i].y-tmp,c[i].y+tmp};
}
sort(a+1,a+cnt+1,cmp);
db h=-inf,ans=0;
F(i,1,cnt)
{
if (a[i].l>h) ans+=a[i].r-a[i].l,h=a[i].r;
else if (a[i].r>h) ans+=a[i].r-h,h=a[i].r;
}
return ans;
} db cal(db l,db r)
{
db mid=(l+r)/2,fl=get(l),fr=get(r),fm=get(mid);
return (r-l)/6*(fl+fr+4*fm);
} db simpson(db l,db r)
{
db mid=(l+r)/2,s1=cal(l,r),s2=cal(l,mid)+cal(mid,r);
if (fabs(s2-s1)<=eps) return s2;
else return simpson(l,mid)+simpson(mid,r);
} int main()
{
Finout();n=Getint();
F(i,1,n)
{
c[i].x=Getint();
c[i].y=Getint();
c[i].r=Getint();
}
sort(c+1,c+n+1,cmp1);
F(i,1,n-1) F(j,i+1,n)
{
if ((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[j].r-c[i].r)*(c[j].r-c[i].r))
{
tag[i]=1;
break;
}
}
F(i,1,n) if (!tag[i]) c[++tot]=c[i];
n=tot;
printf("%.3f\n",simpson(-2000.0,2000.0));
}

  

BZOJ 2178 圆的面积并 ——Simpson积分的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. bzoj 2178 圆的面积并【simpson积分】

    直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段. 然而一定要去掉被其他圆完全覆盖的圆,否则会TLE #include<iostream> #incl ...

  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. Python学习第二弹

    昨天补充: 编码: Unicode ; utf-8 ; GBK       关系:   关键字:1. continue 终止当前循环,进行下一次循环 2. break      终止循环 题6解法2: ...

  2. python更新mysql数据

    >>>cur.execute("update users set username=%s where id=2",("mypython")) ...

  3. Windows10 快捷键

    windows 10快捷键: F1 打开帮助 F2 重命名 F3 打开搜索文件和文件夹 F4 打开地址栏常用的地址 F5 刷新 F11   全屏 选择文件和内容: shift + 上下左右键选择连续的 ...

  4. LeetCode算法1—— 两数之和

    给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target ...

  5. 剑指offer题目系列一

    本篇介绍<剑指offer>第二版中的四个题目:找出数组中重复的数字.二维数组中的查找.替换字符串中的空格.计算斐波那契数列第n项. 这些题目并非严格按照书中的顺序展示的,而是按自己学习的顺 ...

  6. stm8编程tips(stvd)

    编译完成时显示程序占用的flash和ram大小 将附件压缩包中的mapinfo.exe解压到stvd的安装路径\stvd中 在工程上点右键选settings 右侧的选项卡选择Linker,将categ ...

  7. 『AngularJS』ngShow

    原文 描述 ngShow指令显示或隐藏给定的基于标明ngShow属性的HTML元素.元素的显示或隐藏通过在元素上移除或添加ng-hide CSS类属性.".ng-hide"CSS类 ...

  8. 虚拟现实-VR-UE4-编译源代码后,无法运行

    情况是这个样,在一开始我编译后,是可以运行,但是当我重新做系统后,再次运行时,每次都是到加载的18%的时候提示了如下错误 具体解决方法还没有找到,正在努力找中.........,会后续更新 同时希望有 ...

  9. ethday04复杂的智能合约

    复杂的智能合约部署和测试 server--database 客户端服务器数据库模式 以太坊dapp应用程序结构 server --- client 模式 server -- database 传统模式 ...

  10. js/jquery 获取本地文件的文件路劲 获取input框中type=‘file’ 中的文件路径(转载)

     原文:http://blog.csdn.net/niyingxunzong/article/details/16989947 js/jquery 获取本地文件的文件路劲 获取input框中type= ...