code

#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1005;
const double Pi = acos(-1.0);
const double eps = 1e-12;
const double INF = 1e12;
inline int dcmp(double x) {
if(x <= eps && x >= -eps) return 0;
return x > 0 ? 1 : -1;
}
inline double sqr(double x) { return x*x; }
struct Vector {
double x, y;
inline Vector(double _x=0, double _y=0): x(_x), y(_y){}
inline Vector operator *(const double &k)const { return Vector(x*k, y*k) ;}
inline Vector operator +(const Vector &t)const { return Vector(x+t.x, y+t.y); }
inline Vector operator -(const Vector &t)const { return Vector(x-t.x, y-t.y); }
};
struct Point {
double x, y;
inline Point(double _x=0, double _y=0): x(_x), y(_y){}
inline Vector operator -(const Point &t)const { return Vector(x - t.x, y - t.y); }
inline Point operator +(const Vector &t)const { return Point(x + t.x, y + t.y); }
inline double dist(const Point &t) { return sqrt(sqr(x-t.x) + sqr(y-t.y)); }
inline double dist(const double &a, const double &b) { return sqrt(sqr(x-a) + sqr(y-b)); }
};
struct Line {
Point p;
Vector v;
double ang;
inline Line(Point _p=Point(0, 0), Vector _v=Vector(0, 0)): p(_p), v(_v), ang(atan2(v.y, v.x)){}
inline bool operator <(const Line &t)const { return ang < t.ang; }
};
struct Circle {
Point o; double r;
inline Circle(Point _o=Point(0, 0), double _r=0): o(_o), r(_r){}
};
inline double Cross(const Vector &a, const Vector &b) { return a.x*b.y - a.y*b.x; }
inline bool Turn_Left(const Point &a, const Point &b, const Point &c) { return dcmp(Cross(b-a, c-a)) > 0; }
inline bool On_Left(const Line &a, const Point &b) { return dcmp(Cross(a.v, b-a.p)) >= 0; }
inline Point GLI(const Point &P, const Vector &v, const Point &Q, const Vector &w) { //Intersection
Vector u = Q - P;
double k = Cross(u, w) / Cross(v, w);
return P + v*k;
}
inline double Angle_C(const double &a, const double &b, const double &c) { //Triangle's 3 edges
return acos((sqr(a)+sqr(b)-sqr(c))/(2*a*b));
}
inline double Tri_S(const Point &a, const Point &b, const Point &c) { return fabs(Cross(b-a, c-a))/2; }
inline Point rotate(const double &x, const double &y, const double °ree) {
return Point(x*cos(degree)-y*sin(degree), x*sin(degree)+y*cos(degree));
}
int n; Circle cir[MAXN], tmp[MAXN];
inline bool cmp(const Circle &a, const Circle &b) {
return a.o.x-a.r < b.o.x-b.r;
//stO Orz -.- >.< xp XD qwq QAQ ToT QwQ QuQ :-) )-: o-: qx TnT
}
inline bool cmp2(const Circle &a, const Circle &b) {
return a.r > b.r;
}
inline bool chk(const Circle &a, const Circle &b) {
return sqr(a.o.x-b.o.x) + sqr(a.o.y-b.o.y) <= sqr(a.r-b.r);
}
inline void Pre_work() {
sort(cir + 1, cir + n + 1, cmp2);
int cnt = 0;
for(int i = 1; i <= n; ++i) if(cir[i].r) {
bool flg = 1;
for(int j = 1; j <= cnt; ++j)
if(chk(cir[i], tmp[j])) { flg = 0; break; }
if(flg) tmp[++cnt] = cir[i];
}
n = cnt;
for(int i = 1; i <= n; ++i) cir[i] = tmp[i];
sort(cir + 1, cir + n + 1, cmp);
}
int st, ed, tot;
pair<double, double>intervals[MAXN<<1]; inline void getCircleIntersection(const Circle &O, const double &x) {
double len = sqrt(sqr(O.r) - sqr(x-O.o.x));
intervals[++tot] = make_pair(O.o.y-len, O.o.y+len);
} inline double f(double x) {
tot = 0;
for(int i = st; i <= ed; ++i)
if(x < cir[i].o.x+cir[i].r && x > cir[i].o.x-cir[i].r)
getCircleIntersection(cir[i], x);
sort(intervals + 1, intervals + tot + 1);
double L = -INF, R = -INF, res = 0;
for(int i = 1; i <= tot; ++i)
if(intervals[i].first > R)
res += R - L, L = intervals[i].first, R = intervals[i].second;
else R = max(R, intervals[i].second);
return res + (R - L);
}
inline double Simpson(double L, double M, double R, double fL, double fM, double fR, int dep) {
double M1 = (L + M) / 2, M2 = (M + R) / 2;
double fM1 = f(M1), fM2 = f(M2);
double g1 = (M-L) * (fL + 4*fM1 + fM) / 6,
g2 = (R-M) * (fM + 4*fM2 + fR) / 6,
g = (R-L) * (fL + 4*fM + fR) / 6;
if(dep > 11 && fabs(g-g1-g2) < 1e-10) return g;
else return Simpson(L, M1, M, fL, fM1, fM, dep+1) + Simpson(M, M2, R, fM, fM2, fR, dep+1);
}
inline double solve() {
double ans = 0;
for(int i = 1, j; i <= n; ++i) {
double L = cir[i].o.x - cir[i].r, R = cir[i].o.x + cir[i].r;
for(j = i+1; j <= n; ++j)
if(cir[j].o.x - cir[j].r > R) break;
else R = max(R, cir[j].o.x + cir[j].r);
double M = (L + R) / 2;
st = i, ed = i = j-1;
double fL = f(L), fM = f(M), fR = f(R);
ans += Simpson(L, M, R, fL, fM, fR, 0);
}
return ans;
}
int main () {
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%lf%lf%lf", &cir[i].o.x, &cir[i].o.y, &cir[i].r);
Pre_work();
printf("%.3f\n", solve());
}

BZOJ 2178: 圆的面积并 (辛普森积分)的更多相关文章

  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 圆的面积并 ——Simpson积分

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

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

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

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

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

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

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

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

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

  9. BZOJ 1502: [NOI2005]月下柠檬树 [辛普森积分 解析几何 圆]

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1070  Solved: 596[Submit][Status] ...

随机推荐

  1. C++零散知识笔记本

    目录 1.符号 1.1符号输出 1.2运算符 2.基本内置类型 wchar_t 3.内置类型所占字节数 内置类型的简写 4.变量的本质 变量与指针的故事 (1)malloc函数 (2)new关键字 5 ...

  2. input输入框内容变化实时监听

    js实现的文本框内容发生改变立马触发事件简单介绍:本章节介绍一下如何在文本框的内容发生变化的时候,立马触发一个事件执行响应的操作,而不是像是keydown或者keyup事件一样,只能够检测通过键盘输入 ...

  3. kafka producer 生产者客户端参数配置

    在生产者向broker发送消息时,需要配置不同的参数来确保发送成功. acks = all #指定分区中有多少副本必须收到这条消息,生产者才认为这条消息发送成功 acks = 0 #生产者发送消息之后 ...

  4. 【LOJ】#3103. 「JSOI2019」节日庆典

    LOJ#3103. 「JSOI2019」节日庆典 能当最小位置的值一定是一个最小后缀,而有用的最小后缀不超过\(\log n\)个 为什么不超过\(\log n\)个,看了一下zsy的博客.. 假如\ ...

  5. Python二、十、八进制相互转换

    进制转换:先介绍用传统数学方法,再介绍用python内置方法 二进制转十进制: 1101 转为十进制 1*2^(4-1)+1*2^(3-1)+0*2^(2-1)+1*2^(1-1) 即各个位拆开,乘以 ...

  6. java的设计模式的一些链接,站在巨人的肩膀上,才能看的更远。(均来源与网上的各个大牛的博客中)

    创建型抽象工厂模式 http://www.cnblogs.com/java-my-life/archive/2012/03/28/2418836.html工厂方法 http://www.cnblogs ...

  7. 9-MySQL DBA笔记-测试实践

    第9章 测试实践 在第8章中介绍了测试所需要的理论知识,本章将为读者讲述实际的测试过程.实际测试一般包括硬件测试.MySQL基准测试及应用服务压力测试,下面将分别讲述这三方面的内容.此外,测试工具的选 ...

  8. ES6中Map与其他数据结构的互相转换

    最近在学习ES6的基础知识,整理了一下Map与其他数据结构相互转换的写法. Map转为数组的方法 let myMap = new Map([[true, 7], [{foo: 3}, ['abc']] ...

  9. Django rest-framework框架-版本控制

    第一版: from rest_framework.versioning import BaseVersioning class ParamVersion(object): def determine_ ...

  10. elementUI中的loading

    先安装引入 import ElementUI from 'element-ui' import { Loading } from 'element-ui' 在vue的原型链上定义一个打开loading ...