Description

在平面直角坐标系中给定N个圆。已知这些圆两两没有交点,即两圆的关系只存在相离和包含。求这些圆的异或面

积并。异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个圆内则不考虑。

Input

第一行包含一个正整数N,代表圆的个数。接下来N行,每行3个非负整数x,y,r,表示一个圆心在(x,y),半径为r的

圆。保证|x|,|y|,≤10^8,r>0,N<=200000

Output

仅一行一个整数,表示所有圆的异或面积并除以圆周率Pi的结果。

用平衡树维护扫描线与圆的交点

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
typedef long long i64;
const int N=;
int n;
i64 xs[N],ys[N],rs[N],X;
inline i64 p2(i64 x){return x*x;}
inline int _int(){
int x=,c=getchar(),f=;
while(c>||c<){if(c=='-')f=-;c=getchar();}
while(c>&&c<)x=x*+c-,c=getchar();
return x*f;
}
struct pos{
i64 x,y;
int sgn,dep;
i64 r;
double Y(){
i64 a=r-p2(x-X);
if(a<)return y;
return y+sgn*sqrt(a);
}
};
bool operator<(pos a,pos b){
double x=a.Y(),y=b.Y();
if(fabs(x-y)>=.)return x<y;
return a.sgn<b.sgn;
}
struct event{
bool in;
int id;
i64 x(){
if(in)return xs[id]-rs[id];
else return xs[id]+rs[id];
}
}e[N*];
bool operator<(event a,event b){
i64 c=a.x(),d=b.x();
if(c!=d)return c<d;
return a.in<b.in;
}
std::set<pos>line;
int deps[N];
int xp;
i64 xv[N*];
int main(){
n=_int();
for(int i=;i<n;i++){
xs[i]=_int();ys[i]=_int();rs[i]=_int();
xv[i*]=(e[i*]=(event){,i}).x();
xv[i*+]=(e[i*+]=(event){,i}).x();
}
std::sort(e,e+n*);
for(int p=;p<n*;++p){
int id=e[p].id,d;
if(e[p].in){
X=e[p].x();
pos w=(pos){xs[id],ys[id],,,p2(rs[id])};
std::set<pos>::iterator it=line.upper_bound(w);
if(it!=line.end()){
w=*it;
d=(w.sgn==?-w.dep:w.dep);
}else d=;
line.insert((pos){xs[id],ys[id],,d,p2(rs[id])});
line.insert((pos){xs[id],ys[id],-,d,p2(rs[id])});
deps[id]=d;
}else{
X=e[p].x();
line.erase(line.find((pos){xs[id],ys[id],,,p2(rs[id])}));
line.erase(line.find((pos){xs[id],ys[id],-,,p2(rs[id])}));
}
}
i64 ans=;
for(int i=;i<n;i++)ans+=rs[i]*rs[i]*deps[i];
printf("%lld\n",ans);
return ;
}

bzoj4561: [JLoi2016]圆的异或并的更多相关文章

  1. BZOJ4561 JLoi2016 圆的异或并 【扫描线】【set】*

    BZOJ4561 JLoi2016 圆的异或并 Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面积并.异或面积并为:当一片区 ...

  2. bzoj4561: [JLoi2016]圆的异或并 圆的扫描线

    地址:http://www.lydsy.com/JudgeOnline/problem.php?id=4561 题目: 4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec ...

  3. BZOJ4561 JLOI2016圆的异或并(扫描线+平衡树)

    考虑一条扫描线从左到右扫过这些圆.观察某一时刻直线与这些圆的交点,可以发现构成一个类似括号序列的东西,括号的包含关系与圆的包含关系是相同的.并且当扫描线逐渐移动时,括号间的相对顺序不变.于是考虑用se ...

  4. [BZOJ4561][JLOI2016]圆的异或并(扫描线)

    考虑任何一条垂直于x轴的直线,由于圆不交,所以这条直线上的圆弧构成形似括号序列的样子,且直线移动时圆之间的相对位置不变. 将每个圆拆成两边,左端加右端删.每次加圆时考虑它外面最内层的括号属于谁.用se ...

  5. BZOJ4561: [JLoi2016]圆的异或并 计算几何+treap

    因为本题保证两圆之间只有相包含或相离(不用担心两圆重合 因为我没有RE) 所以每个圆之间的相对位置是确定的  也就是可以按极角排序的, 所以可以按横坐标排序后 扫描同时用treap维护加圆删圆(即遇到 ...

  6. 【BZOJ4561】[JLoi2016]圆的异或并 扫描线

    [BZOJ4561][JLoi2016]圆的异或并 Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面积并.异或面积并为:当一 ...

  7. 【BZOJ-4561】圆的异或并 set + 扫描线

    4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 254  Solved: 118[Submit][Statu ...

  8. bzoj 4561: [JLoi2016]圆的异或并

    Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...

  9. BZOJ 4561 [JLoi2016]圆的异或并 ——扫描线

    扫描线的应用. 扫描线就是用数据结构维护一个相对的顺序不变,带修改的东西. 通常只用于一次询问的情况. 抽象的看做一条垂直于x轴直线从左向右扫过去. 这道题目要求求出所有圆的异或并. 所以我们可以求出 ...

随机推荐

  1. java NIO-我们到底能走多远系列(39)

    献给各位: Satisfied MindRed Hayes and Jack RhodesHow many times have you heard someone say,"If I ha ...

  2. 1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost

    报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在loc ...

  3. css 属性积累

    1. letter-spacing:6px;    //属性增加或减少字符间的空白(字符间距) 2. cursor                       // 鼠标移上去的鼠标状态 属性值有: ...

  4. 104. Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. My97DatePickerBeta 时间选择控件用法

    用法说明:只需要调用一个js<script language="javascript" type="text/javascript" src=" ...

  6. c 函数及指针学习 8

    联合体 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h>   union sa     {     double a;     int b; ...

  7. html部分---表单、iframe、frameset及其他字符的用法(以及name、id、value的作用与区别);

    <form action="aa.html" method="post/get"> /action的作用是提交到..,methed是提交方法,用po ...

  8. Codeforces Round #128 (Div. 2)

    A. Two Problems 分两题的过题情况讨论,并且数值均不大,暴力枚举. B. Game on Paper 每次给格子染色后,考虑当前格子在正方形中的位置,然后判断对应的正方形是否都已染色. ...

  9. Codeforces Round #123 (Div. 2)

    A. Let's Watch Football 记时间为\(t\), 则\(bt+(b-a)c>=0\),可得\[t \ge \frac{c(a-b)}{b}\] B. After Traini ...

  10. URAL 1085 Meeting(最短路)

    Meeting Time limit: 2.0 secondMemory limit: 64 MB K friends has decided to meet in order to celebrat ...