跳到正文

题解

题解:AT_arc114_e [ARC114E] Paper Cutting 2

__biu_biu_biu__约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年9月17日
收录
2026年9月17日
更新
2026年11月11日
篇幅
约 2 分钟

版本

  1. v1当前

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

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

  • 把两个点裁掉后的边个数 D=∣h1−h2∣+∣w1−w2∣D=|h_1-h_2|+|w_1-w_2| 需要在该边之后;
  • 内层 i−1i-1 条边需要在该边之后;

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

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

代码
C++
#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;
}
原文
存档评论1 条抓取于