2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest B - Bring Your Own Bombs 离散化+扫描线+计算期望

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

#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 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;

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[3];
} 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 = 0;
        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] > 1) 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] > 1) 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 = 1; i <= n; i++) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        a[++tot] = qus{y1, x1, x2, 1};
        a[++tot] = qus{y2, x1, x2, -1};
        X[++cntx] = x1; X[++cntx] = x2;
        Y[++cnty] = y1; Y[++cnty] = y2;
    }
    for(int i = 1; i <= m; i++) {
        scanf("%d%d%lf%lf", &b[i].x, &b[i].y, &b[i].p[0], &b[i].p[1]);
        b[i].p[0]/=100, b[i].p[1] /= 100, b[i].p[2] = 1 - b[i].p[1] - b[i].p[0];
        X[++cntx] = b[i].x; Y[++cnty] = b[i].y;
    }
    sort(X+1, X+1+cntx); sort(Y+1, Y+1+cnty);
    cntx = unique(X+1, X+1+cntx)-X-1;
    cnty = unique(Y+1, Y+1+cnty)-Y-1;
    for(int i = 1; i <= cntx; i++) val[i] = 1.0;
    for(int i = 1; i <= cnty; i++) val2[i] = 1.0;
    for(int i = 1; i <= tot; i++) {
        a[i].y = lower_bound(Y+1, Y+1+cnty, a[i].y)-Y;
        a[i].x1 = lower_bound(X+1, X+1+cntx, a[i].x1)-X;
        a[i].x2 = lower_bound(X+1, X+1+cntx, a[i].x2)-X;
        if(a[i].op == 1) 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 = 1; i <= m; i++) {
        b[i].x = lower_bound(X+1, X+1+cntx, b[i].x)-X;
        b[i].y = lower_bound(Y+1, Y+1+cnty, b[i].y)-Y;
        if(1-b[i].p[1] > eps) val[b[i].x] *= (1-b[i].p[1]);
        else zero[b[i].x]++;
        if(1-b[i].p[0] > eps) val2[b[i].y] *= (1-b[i].p[0]);
        else zero2[b[i].y]++;
        point[b[i].y].push_back(b[i]);
    }

    for(int i = 1; i <= cntx; i++) {
        if(zero[i]) fact[i] = 0;
        else fact[i] = val[i];
        sum[i] = sum[i-1] + fact[i];
    }
    for(int i = 1; i <= cnty; i++) {
        if(zero2[i]) fact2[i] = 0;
        else fact2[i] = val2[i];
    }
    for(int i = 1; i <= cnty; i++) {
        ans += (Y[i]-Y[i-1]-1)*(people-ret);
        for(PII sgm : in[i]) {
            people += sgm.se-sgm.fi+1;
            people2 += X[sgm.se]-X[sgm.fi]+1-(sgm.se-sgm.fi+1);
            ret += sum[sgm.se] - sum[sgm.fi-1];
            bit.modify(sgm.fi, 1);
            bit.modify(sgm.se+1, -1);
        }
        double res1 = ret, res2 = 0;
        for(Point p : point[i]) {
            if(!bit.sum(p.x)) continue;
            res1 -= fact[p.x];
            changed(p.x, 1-p.p[1]);
            changed2(p.y, 1-p.p[0]);
            res2 += fact[p.x]*fact2[p.y]*p.p[2];
            changem(p.x, 1-p.p[1]);
            changem2(p.y, 1-p.p[0]);
        }
        ans += people - (fact2[i]*res1 + res2) + people2*(1-fact2[i]);
        for(PII sgm : out[i]) {
            people -= sgm.se-sgm.fi+1;
            people2 -= X[sgm.se]-X[sgm.fi]+1-(sgm.se-sgm.fi+1);
            ret -= sum[sgm.se] - sum[sgm.fi-1];
            bit.modify(sgm.fi, -1);
            bit.modify(sgm.se+1, 1);
        }
    }
    printf("%.12f\n", ans);
    return 0;
}

/*
*/

原文地址:https://www.cnblogs.com/CJLHY/p/10051814.html

时间: 2024-11-17 07:41:11

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

2018-2019 ICPC, NEERC, Southern Subregional Contest

目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Cloud Computing(线段树) D.Garbage Disposal(模拟) E.Getting Deals Done(二分) F.Debate(贪心) H.BerOS File Suggestion(后缀自动机) I.Privatization of Roads in Berland(网络流)

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) 体验记

原文链接https://www.cnblogs.com/zhouzhendong/p/CF1070.html 比赛网址:http://codeforces.com/contest/1070 感受 本来只打算玩玩的. 结果玩的海星. 我做 A 题的时候可能比较浮躁吧,各种傻错误,爆了 7 个罚时. 我 A 还没过,cly 神仙已经把 CDK 切光了. 4点半过一会儿,各自回家.cly 要剃头,就咕咕咕了.我本来也要剃的,后来临时决定先打题. 然后过了 A ,顺手切掉了 H 和 F ,开了 E ,猜

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

从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Garbage Disposal Problem E Getting Deals Done Problem F Debate Problem G Monsters and Potions Problem H BerOS File Suggestion Problem I Privatization of

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

http://codeforces.com/contest/1070 A 给你一个d和s,求一个最小的数,使的能整除d,并且每位数的和为s. 如果确定了某n位数取模d的值,那么再计算同样的n位数,取模d也是相同的值时,就多此一举了.比如10%2 == 0  20%2 == 0  同样是两位数,取模2都是等于0.所以取最小的就可以了. 1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$<d, s>$ 表示当前状态模d的值,以及每一位加起来的值 跑最短路,从$<0, 0>  跑到 <0, s>$ 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn = 1e5 +

2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest

地址 Rank Solved A B C D E F G H I J 51/298 6/10 O . O O . . O O O . O: 当场通过 ?: 赛后通过 .: 尚未通过 A Advertising Strategy solved by chelly chelly's solution 签到 B Byteland Trip unsolved C Carpet solved by chelly&ch chelly's solution D Decoding of Varints solv

(并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2061    Accepted Submission(s): 711 Problem Description Jack likes to travel around the wo

2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 591    Accepted Submission(s): 329 Problem Description Elves are very peculiar creatures. As we all know, they can live for a very

【题解】 2015 ACM/ICPC Asia Regional Shenyang Online

[1006] FangFang (暴力枚举) Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 871    Accepted Submission(s): 364 Problem Description Fang Fang says she wants to be remembered. I promise her.