QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#5275. 开玩笑吗?

Statistics

Julia 想要为 $n$ 名玩家设计一款新桌游。作为游戏的一部分,玩家需要决定他们的行动顺序。游戏应该是公平的:每种可能的玩家排列都应以相同的概率被选中。

为了帮助玩家确定这种排列,Julia 想要制作 $n$ 个不同的 $k$ 面骰子。每位玩家掷出自己的骰子并查看点数。点数最小的玩家先行,点数第二小的玩家排第二,以此类推。为了确保不会出现平局,所有骰子上使用的数字必须各不相同。

这可能是一个很好的数学问题,但由于这是一场编程竞赛,我们允许一定的误差。我们要求你为这个游戏设计骰子,但获得各种排列的概率可能会略有不同。如果任意两种排列的概率的相对差异不超过 $0.2\%$,你的解法将被接受。

形式化地说,掷出所有 $n$ 个骰子共有 $k^n$ 种不同的结果。对于每种排列 $P$,我们可以计算导致该排列的场景数量 $f(P)$。对于任意两种排列 $P$ 和 $Q$,必须满足以下条件:$\frac{|f(P)-f(Q)|}{\max(f(P), f(Q))} \le 0.002$。

你可以选择任意 $k$,但 $k$ 不能超过 $120$。

输入格式

唯一的一行包含一个整数 $n$ —— 玩家人数 ($2 \le n \le 5$)。

输出格式

第一行输出一个整数 $k$ —— 每个骰子的面数 ($1 \le k \le 120$)。

接下来的 $n$ 行,每行描述一个骰子。对于每个骰子,输出 $k$ 个 $1$ 到 $k \cdot n$ 之间的整数。所有骰子上使用的整数必须各不相同。

样例

样例输入 1

2

样例输出 1

2
1 4
2 3

样例输入 2

3

样例输出 2

16
3 7 9 10 12 17 18 19 28 32 33 35 38 40 43 48
1 2 6 13 14 20 22 26 27 29 30 36 37 39 44 46
4 5 8 11 15 16 21 23 24 25 31 34 41 42 45 47

说明

在第一个样例测试中,两种玩家排列的概率均为 $\frac{1}{2}$。

在第二个样例测试中,共有 $16^3 = 4096$ 种可能的场景。排列 $[2, 1, 3]$ 和 $[3, 1, 2]$ 各出现 $682$ 次,而其他每种排列各出现 $683$ 次。因此,最可能与最不可能的排列之间的相对差异为 $\frac{683-682}{683} \approx 0.146\%$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.