题解:AT_arc114_e [ARC114E] Paper Cutting 2

· · 题解

考虑将裁边个数的期望转成裁每条边的概率之和。

则成功裁从内往外数第 i 条边的概率为:

即 D+i-1+1 条边内,该边需要最先裁掉,概率为 \frac{1}{D+i}。

则答案即为 \sum \frac{1}{D+i}+1,注意有四个方向。

:::info[代码]

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int l[4];
int qpow(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return res;
}
signed main() {
    int h, w, a, b, c, d, ans = 0;
    cin >> h >> w >> a >> b >> c >> d;
    l[0] = min(a, c) - 1, l[1] = h - max(a, c), l[2] = min(b, d) - 1, l[3] = w - max(b, d);
    ans = 1;
    for(int i = 0; i <= 3; i++) {
        for(int j = 1; j <= l[i]; j++) {
            ans = (ans + qpow(j + abs(a - c) + abs(b - d), mod - 2) % mod) % mod;
        }
    }
    cout << ans;
}

:::