QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#9948. 魔法12个月

الإحصائيات

现在是新年前夕,也是玩纸牌游戏 Magic 12 Months 来祈求来年好运的最佳时机。BaoBao 刚从口袋里掏出一副标准的 52 张扑克牌(不含大小王),决定玩这个游戏。游戏规则如下:

1. 设置

1.1. 从 52 张牌中移除四张 ‘K’。 1.2. 将剩余的 48 张牌洗匀,并以相等的概率随机分成 12 堆(每堆 4 张),牌面朝下。

2. 游戏过程

2.1. 令 $p = 1$。 2.2. 翻开第 $p$ 堆牌顶的牌,检查其点数 $r$,并将该牌弃置。 2.3. 如果 $r$ 是数字,令 $p = r$;如果 $r = \text{‘A’}$,令 $p = 1$;如果 $r = \text{‘J’}$,令 $p = 11$;如果 $r = \text{‘Q’}$,令 $p = 12$。 2.4. 如果第 $p$ 堆牌为空,游戏结束;否则回到步骤 2.2。

当游戏结束时,如果某点数 $m$ 的 4 张牌均已被翻开并弃置,则表示来年的第 $m$ 个月是幸运月。

BaoBao 正在进行游戏,且已经弃置了 $n$ 张牌。他想知道当游戏结束时,来年第 $i$ 个月是幸运月的概率(对于所有 $1 \le i \le 12$)。给定这 $n$ 张牌,请帮他计算答案。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$(约 100),表示测试数据组数。对于每组测试数据:

第一行包含一个整数 $n$ ($0 \le n \le 48$),表示已翻开的牌数,随后是 $n$ 张牌的点数 $r_1, r_2, \dots, r_n$ ($r_i \in \{\text{A}, 2, 3, 4, 5, 6, 7, 8, 9, 10, \text{J}, \text{Q}\}$),按翻开顺序以空格分隔。保证输入描述了游戏的一种合法且可能的情况。

输出格式

对于每组测试数据,输出一行,包含 12 个以空格分隔的数字,其中第 $i$ 个数字表示第 $i$ 个月是幸运月的概率。

你应该以最简分数形式 $A/B$ 输出概率,其中 $A$ 和 $B$ 互质。特别地,如果概率为 0,输出 0;如果概率为 1,输出 1。

请勿在每行末尾输出多余空格,否则你的答案可能会被判定为错误!

样例

输入 1

3
30 9 Q 10 J Q 10 J 10 J J 8 5 7 6 5 7 6 7 6 6 3 A 2 4 A 2 4 2 4 4
0
7 2 A 3 A 4 A A

输出 1

1 2/3 2/5 1 1/2 1 2/3 2/5 2/5 2/3 1 1/2
1 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2
1 0 0 0 0 0 0 0 0 0 0 0

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.