扫描线一边扫一边算期望,细节比较多。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define PLL pair<LL, LL>
#define ull unsigned long long
using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, m, tot, X[N], cntx, Y[N], cnty, zero[N], zero2[N], people, people2;
double val[N], val2[N], sum[N], fact[N], fact2[N], ret, ans; struct qus {
int y, x1, x2, op;
} a[N];
struct Point {
int x, y;
double p[];
} b[N]; struct Bit {
int a[N];
void modify(int x, int v) {
for(int i = x; i < N; i+=i&-i)
a[i] += v;
}
int sum(int x) {
int ans = ;
for(int i = x; i; i-=i&-i)
ans += a[i];
return ans;
}
} bit; vector<Point> point[N];
vector<PII> in[N], out[N]; inline void changed(int x, double p) {
if(zero[x] > ) return;
if(p < eps) fact[x] = val[x];
else fact[x] /= p;
}
inline void changem(int x, double p) {
fact[x] *= p;
}
inline void changed2(int y, double p) {
if(zero2[y] > ) return;
if(p < eps) fact2[y] = val2[y];
else fact2[y] /= p;
}
inline void changem2(int x, double p) {
fact2[x] *= p;
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
a[++tot] = qus{y1, x1, x2, };
a[++tot] = qus{y2, x1, x2, -};
X[++cntx] = x1; X[++cntx] = x2;
Y[++cnty] = y1; Y[++cnty] = y2;
}
for(int i = ; i <= m; i++) {
scanf("%d%d%lf%lf", &b[i].x, &b[i].y, &b[i].p[], &b[i].p[]);
b[i].p[]/=, b[i].p[] /= , b[i].p[] = - b[i].p[] - b[i].p[];
X[++cntx] = b[i].x; Y[++cnty] = b[i].y;
}
sort(X+, X++cntx); sort(Y+, Y++cnty);
cntx = unique(X+, X++cntx)-X-;
cnty = unique(Y+, Y++cnty)-Y-;
for(int i = ; i <= cntx; i++) val[i] = 1.0;
for(int i = ; i <= cnty; i++) val2[i] = 1.0;
for(int i = ; i <= tot; i++) {
a[i].y = lower_bound(Y+, Y++cnty, a[i].y)-Y;
a[i].x1 = lower_bound(X+, X++cntx, a[i].x1)-X;
a[i].x2 = lower_bound(X+, X++cntx, a[i].x2)-X;
if(a[i].op == ) in[a[i].y].push_back(mk(a[i].x1, a[i].x2));
else out[a[i].y].push_back(mk(a[i].x1, a[i].x2));
}
for(int i = ; i <= m; i++) {
b[i].x = lower_bound(X+, X++cntx, b[i].x)-X;
b[i].y = lower_bound(Y+, Y++cnty, b[i].y)-Y;
if(-b[i].p[] > eps) val[b[i].x] *= (-b[i].p[]);
else zero[b[i].x]++;
if(-b[i].p[] > eps) val2[b[i].y] *= (-b[i].p[]);
else zero2[b[i].y]++;
point[b[i].y].push_back(b[i]);
} for(int i = ; i <= cntx; i++) {
if(zero[i]) fact[i] = ;
else fact[i] = val[i];
sum[i] = sum[i-] + fact[i];
}
for(int i = ; i <= cnty; i++) {
if(zero2[i]) fact2[i] = ;
else fact2[i] = val2[i];
}
for(int i = ; i <= cnty; i++) {
ans += (Y[i]-Y[i-]-)*(people-ret);
for(PII sgm : in[i]) {
people += sgm.se-sgm.fi+;
people2 += X[sgm.se]-X[sgm.fi]+-(sgm.se-sgm.fi+);
ret += sum[sgm.se] - sum[sgm.fi-];
bit.modify(sgm.fi, );
bit.modify(sgm.se+, -);
}
double res1 = ret, res2 = ;
for(Point p : point[i]) {
if(!bit.sum(p.x)) continue;
res1 -= fact[p.x];
changed(p.x, -p.p[]);
changed2(p.y, -p.p[]);
res2 += fact[p.x]*fact2[p.y]*p.p[];
changem(p.x, -p.p[]);
changem2(p.y, -p.p[]);
}
ans += people - (fact2[i]*res1 + res2) + people2*(-fact2[i]);
for(PII sgm : out[i]) {
people -= sgm.se-sgm.fi+;
people2 -= X[sgm.se]-X[sgm.fi]+-(sgm.se-sgm.fi+);
ret -= sum[sgm.se] - sum[sgm.fi-];
bit.modify(sgm.fi, -);
bit.modify(sgm.se+, );
}
}
printf("%.12f\n", ans);
return ;
} /*
*/

2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest B - Bring Your Own Bombs 离散化+扫描线+计算期望的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)

    2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  6. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

  7. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

  8. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  9. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

随机推荐

  1. Kafka 0.8 Controller设计机制和状态变化

    在kafka集群中,其中一个broker server作为中央控制器Control,负责管理分区和副本状态并执行管理着这些分区的重新分配. 下面说明如何通过中央控制器操作分区和副本的状态. 名词解释 ...

  2. bzoj千题计划114:bzoj1791: [Ioi2008]Island 岛屿

    http://www.lydsy.com/JudgeOnline/problem.php?id=1791 就是求所有基环树的直径之和 加手工栈 #include<cstdio> #incl ...

  3. JS的执行和加载(笔记)

    无论当前JS代码是内嵌还是在外链文件中,页面的下载和渲染都必须停下来等待脚本执行完成.JS执行过程耗时越久,浏览器等待响应用户输入的时间就越长.当浏览器遇到内嵌的JS代码时会停止处理页面,先执行JS代 ...

  4. asp.net中GridView传多个值到其它页面的方法

    网站开发中,在页面之间的跳转,经常会用到传值,其中可能会传递多个值. 一.CommadArgument传多个值到其他页面. 像Gridview dataList repeater等数据绑定控件中,可以 ...

  5. Android Dalvik和JVM的区别

    JVM运行的Java字节码,它从.class文件或Jar包中加载字节码然后执行: Dalvik 运行的是 dex 文件(Dalvik Executable),生成APK时,Dx工具把所有.class文 ...

  6. CodeForces 714A

    Description Today an outstanding event is going to happen in the forest — hedgehog Filya will come t ...

  7. Python文件操作-文件的增删改查

    需求:对文件进行增删改查 由于时间原因,本次代码没有增加任何注释,如有疑问,请联系编辑者:闫龙 其实我也是醉了,看着这些个代码,我脑袋也特么大了,没办法,大神说了,不让用新知识,只可以使用学过的,所以 ...

  8. 【译】第九篇 Replication:复制监视器

    本篇文章是SQL Server Replication系列的第九篇,详细内容请参考原文. 复制监视器允许你查看复制配置组件的健康状况.这一篇假设你遵循前八篇,并且你已经有一个合并发布和事务发布.启动复 ...

  9. 工具_HBuilder工具使用技巧

    https://www.cnblogs.com/xiaohouzai/p/7696152.html

  10. D - Doing Homework HDU - 1074 (状压dp)

    题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求  10 ...