题目链接:BZOJ - 2178

题目分析

用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求。

注意:1)Eps要设成 1e-13  2)要去掉被其他圆包含的圆。

代码

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; typedef double LF; const LF Eps = 1e-13; const int MaxN = 1000 + 5; int n, Lc, Rc, Top, Tot; LF Lx, Rx, Ans; inline LF gmin(LF a, LF b) {return a < b ? a : b;}
inline LF gmax(LF a, LF b) {return a > b ? a : b;}
inline LF Sqr(LF x) {return x * x;} struct Point
{
LF x, y;
Point() {}
Point(LF a, LF b)
{
x = a; y = b;
}
}; inline LF Dis(Point p1, Point p2)
{
return sqrt(Sqr(p1.x - p2.x) + Sqr(p1.y - p2.y));
} struct Circle
{
Point o;
LF r;
} C[MaxN], S[MaxN]; inline bool Cmp1(Circle c1, Circle c2)
{
return c1.r < c2.r;
} inline bool Cmp2(Circle c1, Circle c2)
{
return c1.o.x - c1.r < c2.o.x - c2.r;
} bool Del[MaxN]; struct Segment
{
LF l, r;
} Seg[MaxN]; inline bool Cmp3(Segment s1, Segment s2)
{
return s1.l < s2.l;
} inline LF f(LF x)
{
LF ret = 0.0, p, q, Hi;
Top = 0;
for (int i = Lc; i <= Rc; ++i)
{
if (x <= S[i].o.x - S[i].r || x >= S[i].o.x + S[i].r) continue;
Hi = sqrt(Sqr(S[i].r) - Sqr(S[i].o.x - x));
Seg[++Top].l = S[i].o.y - Hi; Seg[Top].r = S[i].o.y + Hi;
}
sort(Seg + 1, Seg + Top + 1, Cmp3);
for (int i = 1, j; i <= Top; ++i)
{
p = Seg[i].l; q = Seg[i].r;
for (j = i + 1; j <= Top; ++j)
{
if (Seg[j].l > q) break;
if (Seg[j].r > q) q = Seg[j].r;
}
ret += q - p; i = j - 1;
}
return ret;
} inline LF Simpson(LF l, LF r, LF fl, LF fmid, LF fr)
{
return (fl + 4.0 * fmid + fr) * (r - l) / 6.0;
} inline LF RSimpson(LF l, LF r, LF fl, LF fmid, LF fr)
{
LF mid, p, q, x, y, z;
mid = (l + r) / 2.0;
p = f((l + mid) / 2.0); q = f((mid + r) / 2.0);
x = Simpson(l, r, fl, fmid, fr);
y = Simpson(l, mid, fl, p, fmid);
z = Simpson(mid, r, fmid, q, fr);
if (fabs(x - y - z) < Eps) return y + z;
else return RSimpson(l, mid, fl, p, fmid) + RSimpson(mid, r, fmid, q, fr);
} int main()
{
scanf("%d", &n);
int a, b, c;
for (int i = 1; i <= n; ++i)
{
scanf("%d%d%d", &a, &b, &c);
C[i].o = Point((LF)a, (LF)b);
C[i].r = (LF)c;
}
sort(C + 1, C + n + 1, Cmp1);
memset(Del, 0, sizeof(Del));
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if (Dis(C[i].o, C[j].o) <= C[j].r - C[i].r)
{
Del[i] = true;
break;
}
Tot = 0;
for (int i = 1; i <= n; ++i)
if (!Del[i]) S[++Tot] = C[i];
sort(S + 1, S + Tot + 1, Cmp2);
Ans = 0.0;
for (int i = 1, j; i <= Tot; ++i)
{
Lc = i; Rc = i; Lx = S[i].o.x - S[i].r; Rx = S[i].o.x + S[i].r;
for (j = i + 1; j <= Tot; ++j)
{
if (S[j].o.x - S[j].r > Rx) break;
if (S[j].o.x + S[j].r > Rx) Rx = S[j].o.x + S[j].r;
}
Rc = j - 1; i = j - 1;
Ans += RSimpson(Lx, Rx, f(Lx), f((Lx + Rx) / 2.0), f(Rx));
}
printf("%.3lf\n", Ans);
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积分】

    直接套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. hadoop错误Ignoring exception during close for org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException Spill failed

    1.错误    Ignoring exception during close for org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bd ...

  2. 从源码角度理解android动画Interpolator类的使用

    做过android动画的人对Interpolator应该不会陌生,这个类主要是用来控制android动画的执行速率,一般情况下,如果我们不设置,动画都不是匀速执行的,系统默认是先加速后减速这样一种动画 ...

  3. ubuntu常用文件搜索命令 分类: linux 学习笔记 ubuntu 2015-07-05 15:40 84人阅读 评论(0) 收藏

    1.find find [搜索路径] [搜索关键字] 比如查找/test中文件名为t5.tmp的文件: 查找根目录下大于100M的文件 注意,这里的204800单位是块,1块=512字节 在根目录下查 ...

  4. 程序员带你学习安卓开发,十天快速入-对比C#学习java语法

    关注今日头条-做全栈攻城狮,学代码也要读书,爱全栈,更爱生活.提供程序员技术及生活指导干货. 如果你真想学习,请评论学过的每篇文章,记录学习的痕迹. 请把所有教程文章中所提及的代码,最少敲写三遍,达到 ...

  5. java的集合框架之一

    java是一套很成熟的东西,很多商用的东西都喜欢用它,用的人多,稳定.不过一般也不怎么说起它,因为太常见了,私下里说,写java应用层得就像农民工,每一处都是搭积木,根据设计师的东西如何优雅地搭好积木 ...

  6. getSharedPreferences()与getSharedPreferences()与getDefaultSharedPreferences()的区别

    http://blog.csdn.net/ah200614435/article/details/7869681 一直迷惑于这三个方法的关系,最近忙完项目,好好的分析一下. 如果你熟悉Context那 ...

  7. [Twisted] 事件驱动模型

    在事件驱动编程中,多个任务交替执行,并且在单一线程控制下进行.当执行I/O或者其他耗时操作时,回调函数会被注册到事件循环. 当I/O完成时,执行回调.回调函数描述了在事件完成之后,如何处理事件.事件循 ...

  8. 【html】【1】html的简单结构

    1>我们为什么能打开html网页 计算机本身有个配置文件后缀打开程序的默认,好比:.txt =>记事本打开   html=>浏览器打开 文件一切的鼻祖都起源于.txt文件,你只要修改 ...

  9. Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)

    题目描述 We know thatif a phone number A is another phone number B's prefix, B is not able to becalled. ...

  10. hdu 1788 Chinese remainder theorem again(最小公倍数)

    Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,-,mk两两互素,则下面同余方程组: x≡a1(mod m1) x≡a2( ...