QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100

#11903. 掷硬币

統計

Alice 和 Bob 各自选择了一个仅包含正面(H)和反面(T)的字符串。随后,一枚公平的硬币被不断抛掷,直到抛掷出的连续序列与其中一个或两个字符串匹配为止。如果 Alice 的字符串先出现,则 Alice 获胜;如果 Bob 的字符串先出现,则 Bob 获胜。两个字符串也有可能同时出现,在这种情况下,比赛为平局。

给定这两个字符串,求这三种结果的概率。

输入格式

输入的第一行是 Alice 的字符串,第二行是 Bob 的字符串。这些字符串仅包含 H 和 T,且长度在 1 到 20 之间(含 1 和 20)。

输出格式

输出包含三行,每行一个实数。依次为 Alice 获胜的概率、Bob 获胜的概率以及平局的概率。

如果你的答案与正确答案的误差不超过 $10^{-8}$,则视为正确。

样例

样例输入 1

H
T

样例输出 1

0.500000000000
0.500000000000
0.000000000000

样例输入 2

HHT
HTH

样例输出 2

0.666666666667
0.333333333333
0.000000000000

样例输入 3

THH
HH

样例输出 3

0.000000000000
0.250000000000
0.750000000000

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.