考虑将裁边个数的期望转成裁每条边的概率之和。
则成功裁从内往外数第 条边的概率为:
- 把两个点裁掉后的边个数 需要在该边之后;
- 内层 条边需要在该边之后;
即 条边内,该边需要最先裁掉,概率为 。
则答案即为 ,注意有四个方向。
代码
#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;
}