题面

传送门

题解

首先您得会用格林公式计算圆的面积并

这里只需要动态维护一下圆弧就可以了

时间复杂度\(O(n^2\log n)\)

//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2005;const double Pi=acos(-1.0);
struct Point{
int x,y;
inline Point(){}
inline Point(R int xx,R int yy):x(xx),y(yy){}
inline Point operator +(const Point &b)const{return Point(x+b.x,y+b.y);}
inline Point operator -(const Point &b)const{return Point(x-b.x,y-b.y);}
inline double norm(){return sqrt(x*x+y*y);}
inline double ang(){return atan2(y,x);}
};
struct Cir{
Point p;int r;
inline double oint(R double t1,R double t2){
return r*(r*(t2-t1)+p.x*(sin(t2)-sin(t1))-p.y*(cos(t2)-cos(t1)));
}
inline bool in(const Cir &b)const{return (p-b.p).norm()+b.r<=r;}
inline bool out(const Cir &b)const{return r+b.r<=(p-b.p).norm();}
}c[N];
struct node{
double l,r;
inline node(R double ll,R double rr):l(ll),r(rr){}
inline bool operator <(const node &b)const{return r<b.r;}
};
set<node>s[N];double res;int n;bool vis[N];
typedef set<node>::iterator IT;
inline void upd(R double &ang){
if(ang<-Pi)ang+=2*Pi;
if(ang>Pi)ang-=2*Pi;
}
void remove(int id,double l,double r){
for(IT it=s[id].lower_bound(node(0,l)),tmp;it!=s[id].end()&&it->l<r;it=tmp){
double nl=it->l,nr=it->r;
tmp=it,++tmp,s[id].erase(it),res-=c[id].oint(nl,nr);
if(nl<l)s[id].insert(node(nl,l)),res+=c[id].oint(nl,l);
if(nr>r)s[id].insert(node(r,nr)),res+=c[id].oint(r,nr);
}
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%*d%d",&n);
fp(i,1,n){
vis[i]=1;
scanf("%d%d%d",&c[i].p.x,&c[i].p.y,&c[i].r);
fp(j,1,i-1)if(vis[j]){
if(c[j].r>=c[i].r&&c[j].in(c[i])){vis[i]=0;break;}
if(c[i].r>c[j].r&&c[i].in(c[j]))vis[j]=0,remove(j,-Pi,Pi);
}
if(!vis[i]){printf("%.10lf\n",res*0.5);continue;}
res+=c[i].r*c[i].r*Pi*2,s[i].insert(node(-Pi,Pi));
fp(j,1,i-1)if(vis[j]&&!c[i].out(c[j])){
double dis=(c[i].p-c[j].p).norm(),ang,cur,l,r;
cur=(c[j].p-c[i].p).ang();
ang=acos((dis*dis+c[i].r*c[i].r-c[j].r*c[j].r)/(2*c[i].r*dis));
l=cur-ang,r=cur+ang,upd(l),upd(r);
if(l<=r)remove(i,l,r);else remove(i,-Pi,r),remove(i,l,Pi);
cur=(c[i].p-c[j].p).ang();
ang=acos((dis*dis+c[j].r*c[j].r-c[i].r*c[i].r)/(2*c[j].r*dis));
l=cur-ang,r=cur+ang,upd(l),upd(r);
if(l<r)remove(j,l,r);else remove(j,-Pi,r),remove(j,l,Pi);
}
printf("%.10lf\n",res*0.5);
}
return 0;
}

UOJ#419. 【集训队作业2018】圆形(格林公式)的更多相关文章

  1. uoj #450[集训队作业2018]复读机

    传送门 \(d=1\),那么任何时刻都可以\(k\)个复读机的一种,答案为\(k^n\) \(d>1\),可以枚举某个复读机的复读次数(必须是\(d\)的倍数),然后第\(i\)个复读时间为\( ...

  2. UOJ 422 [集训队作业2018] 小Z的礼物 min-max容斥 期望 轮廓线dp

    LINK:小Z的礼物 太精髓了 我重学了一遍min-max容斥 重写了一遍按位或才写这道题的. 还是期望多少时间可以全部集齐. 相当于求出 \(E(max(S))\)表示最后一个出现的期望时间. 根据 ...

  3. UOJ #449. 【集训队作业2018】喂鸽子

    UOJ #449. [集训队作业2018]喂鸽子 小Z是养鸽子的人.一天,小Z给鸽子们喂玉米吃.一共有n只鸽子,小Z每秒会等概率选择一只鸽子并给他一粒玉米.一只鸽子饱了当且仅当它吃了的玉米粒数量\(≥ ...

  4. 【UOJ#450】【集训队作业2018】复读机(生成函数,单位根反演)

    [UOJ#450][集训队作业2018]复读机(生成函数,单位根反演) 题面 UOJ 题解 似乎是\(\mbox{Anson}\)爷的题. \(d=1\)的时候,随便怎么都行,答案就是\(k^n\). ...

  5. 【UOJ#422】【集训队作业2018】小Z的礼物(min-max容斥,轮廓线dp)

    [UOJ#422][集训队作业2018]小Z的礼物(min-max容斥,轮廓线dp) 题面 UOJ 题解 毒瘤xzy,怎么能搬这种题当做WC模拟题QwQ 一开始开错题了,根本就不会做. 后来发现是每次 ...

  6. UOJ#418. 【集训队作业2018】三角形

    #418. [集训队作业2018]三角形 和三角形没有关系 只要知道儿子放置的顺序,就可以直接模拟了 记录历史最大值 用一个pair(a,b):之后加上a个,期间最大值为增加b个 合并? A1+A2= ...

  7. UOJ#422. 【集训队作业2018】小Z的礼物

    #422. [集训队作业2018]小Z的礼物 min-max容斥 转化为每个集合最早被染色的期望时间 如果有x个选择可以染色,那么期望时间就是((n-1)*m+(m-1)*n))/x 但是x会变,中途 ...

  8. UOJ#428. 【集训队作业2018】普通的计数题

    #428. [集训队作业2018]普通的计数题 模型转化好题 所以变成统计有标号合法的树的个数. 合法限制: 1.根标号比子树都大 2.如果儿子全是叶子,数量B中有 3.如果存在一个儿子不是叶子,数量 ...

  9. uoj450 【集训队作业2018】复读机(生成函数,单位根反演)

    uoj450 [集训队作业2018]复读机(生成函数,单位根反演) uoj 题解时间 首先直接搞出单个复读机的生成函数 $ \sum\limits_{ i = 0 }^{ k } [ d | i ] ...

  10. [UOJ422][集训队作业2018]小Z的礼物——轮廓线DP+min-max容斥

    题目链接: [集训队作业2018]小Z的礼物 题目要求的就是最后一个喜欢的物品的期望得到时间. 根据$min-max$容斥可以知道$E(max(S))=\sum\limits_{T\subseteq ...

随机推荐

  1. C# 单例模式的五种写法

    1.简单实现           C#   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 public sealed c ...

  2. 移动端Android软键盘遮住输入框解决!

    在使用vue的情况下,在输入框中添加 <textarea class="textarea" @click="isAndroid" :maxlength=& ...

  3. 2.7 Sobel导数

    OpenCV函数 Sobel(src_gray,grad_x/grad_y,ddepth,x_order,y_order,scale,delta,BORDER_DEFAULT ) Scharr( ) ...

  4. README.md 编写

    Spring Boot Demo =========================== 该文件用来测试和展示书写README的各种markdown语法.GitHub的markdown语法在标准的ma ...

  5. web程序打包详解

       重要更新:鉴于很多小伙伴们说看不到图,我这边换了几个浏览器看了下,都看得到的,估计是网速问题,请耐心等待,另外,为了更好的方便大家学习,特此提供源码以及一个word文档,word文档就是本文内容 ...

  6. Linux top命令总结

    一:在bash里输入top后出现的数据当中目前自己容易理解的有 1.task:中的 num total表示总共有num个进程:num running是正在运行的进程数:num sleeping是正在休 ...

  7. shell字符串分割截取和转换总结

    一:字符串的截取 假定有定义变量VAR=mm/aa/bb/dd 1.获取字符串长度:echo "${#VAR}",即输出11: 2.非贪婪模式删除左边的,保留右边的:echo &q ...

  8. 统计UPD丢包工具

    下载位置:https://github.com/eyjian/libmooon/tree/master/shell #!/bin/bash # 统计UPD丢包工具 # 可选参数1:统计间隔(单位:秒, ...

  9. TinyMCE Editor

    TinyMCE Editor(https://www.tinymce.com/features/) is an online text editor, it is used to write post ...

  10. (01背包)Buy the souvenirs (hdu 2126)

    http://acm.hdu.edu.cn/showproblem.php?pid=2126 Buy the souvenirs Time Limit: 10000/1000 MS (Java/Oth ...