题解:AT_arc114_e [ARC114E] Paper Cutting 2
__biu_biu_biu__ · · 题解
考虑将裁边个数的期望转成裁每条边的概率之和。
则成功裁从内往外数第
- 把两个点裁掉后的边个数
D=|h_1-h_2|+|w_1-w_2| 需要在该边之后; - 内层
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;
}
:::