QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#14382. 随机回合连接游戏

統計

Alice 和 Bob 在一个 $8 \times 8$ 的方格棋盘上玩一个随机轮流占位的连通游戏。在每一步中,玩家通过抛一枚均匀的硬币来决定谁获得这一步的操作权。也就是说,无论之前是谁操作,Alice 和 Bob 都有 $50\%$ 的概率获得下一步的操作权。一旦玩家获得操作权,他/她将在一个空单元格中放置一枚自己的棋子。Alice 和 Bob 都随机进行游戏。也就是说,如果当前有 $k$ 个空单元格,每个空单元格被选中的概率均为 $1/k$。一旦 Alice 的棋子将棋盘的顶边和底边连接起来,她就赢得了游戏。类似地,一旦 Bob 的棋子将棋盘的左边和右边连接起来,他就赢得了游戏。棋子只能水平或垂直连接,不能对角线连接。你的任务是计算 Alice 和 Bob 获胜的概率。

输入格式

第一行是测试用例的数量。每个测试用例包含 8 行,每行包含 8 个字符,表示棋盘的当前状态。Alice 占用的单元格标记为 “A”,Bob 占用的单元格标记为 “B”,空单元格标记为 “.”。测试用例之间有一个空行。

输出格式

对于每个测试用例,输出 Alice 和 Bob 获胜的概率,精度保留到小数点后 6 位。

样例

输入样例 1

4
....A...
....A...
....A...
....A...
....A...
....A...
....A...
....A...

....A...
....A...
....A...
....A...
BBBB.BBB
....A...
....A...
....A...

....A...
....A...
....A...
BBBBA...
...ABBBB
...A....
...A....
...A....

........
........
........
........
........
........
........
.......A

输出样例 1

Alice 1.000000 Bob 0.000000
Alice 0.500000 Bob 0.500000
Alice 0.000000 Bob 0.000000
Alice 0.223093 Bob 0.198498

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.