QOJ.ac

QOJ

Limite de temps : 2000 s Limite de mémoire : 262144 MB Points totaux : 100 Hackable ✓

#417. 棋盘闪击

Statistiques

在这个问题中,你需要快速找出棋盘游戏结束时的最终局面。

考虑一个 $8 \times 8$ 的方格棋盘。初始时棋盘为空。两名玩家轮流行动。第一名玩家控制白子,第二名玩家控制黑子。每一回合包含玩家棋子的移动或跳跃。

进行移动时,玩家选择四个方向之一,并将其所有棋子同时向该方向移动一格。如果棋子移出棋盘,它就会消失。此外,对于该方向上移动时无法到达的八个边界格子,玩家可以在这些格子中放置新的己方棋子。如果棋子出现在包含对方棋子的格子上,该对方棋子将从棋盘上消失。

进行跳跃时,玩家将其所有棋子同时转移到绕棋盘中心旋转 90 度后的位置。白子顺时针旋转,黑子逆时针旋转。与移动后相同,如果棋子出现在包含对方棋子的格子上,该对方棋子将从棋盘上消失。

两位玩家约定根据随机数生成器产生的值轮流行动:第一个随机数决定第一名玩家的回合,第二个随机数决定第二名玩家的回合,第三个随机数指定第一名玩家的下一回合,依此类推。

给定 64 位有符号整数类型的线性同余伪随机数生成器的参数 $a, c$ 和 $s$。该生成器的工作方式如下:为了获得下一个随机数,执行赋值 $s_{new} := s_{old} \cdot a + c$,结果截断为 64 位有符号整数类型,存储为 $s$ 的新值并作为下一个随机数返回。

回合由随机数的高 11 位决定的数 $p$ 确定(换句话说,$p$ 是 $s$ 除以 $2^{53}$ 向零取整的结果)。如果 $p < 0$,则该回合为跳跃。否则,该回合为移动,位 8(乘以 1)和位 9(乘以 2)构成方向编号(0 为上,1 为左,2 为下,3 为右),位 0 到 7 指定哪八个格子将包含新棋子。格子按从上到下或从左到右(取决于方向)编号为 0 到 7。

给定数字 $a, c, s$ 以及半回合数 $n$,求棋盘上的最终局面。半回合是指其中一名玩家的回合。保证 $n$ 为偶数。此外,保证在除样例外的所有评测数据中,三元组 $a, c, s$ 是从所有使得线性同余生成器周期恰好为 $2^{64}$ 的三元组中均匀随机选择的。

输入格式

输入的第一行包含一个整数 $n$(半回合数),以及随机数生成器的参数 $a, c$ 和 $s$($2 \le n \le 30\,000\,000$,$n$ 为偶数,$-2^{63} \le a, c, s < 2^{63}$,生成器周期恰好为 $2^{64}$)。

输出格式

输出八行,每行八个字符,表示所有回合完成后的棋盘状态。用字符 “.” 表示空位,用 “W” 表示白子,用 “B” 表示黑子。

样例

输入 1

10 12345678901234565 23456789012345679 12345678

输出 1

.BB.....
......BB
........
WW......
WW......
W......B
W.......
.W......

说明

下表显示了样例中 $s$ 的序列值、$p$ 的值以及 $p$ 的特定位。

$s$ $p$ bit 10 bits 9–8 bits 7–0
8800325836438854357 977 0 11 11010001
-6158326326699848968 -684 1 01 01010100
-8075422879926989273 -897 1 00 01111111
3701688810043832978 410 0 01 10011010
1958856781360031529 217 0 00 11011001
594250524398489244 65 0 00 01000001
-6137059809998356901 -682 1 01 01010110
634828852634288534 70 0 00 01000110
8001533107637205053 888 0 11 01111000
-4716194469178570240 -524 1 01 11110100

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.