CF476B.Dreamoon and WiFi
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
- Go 1 unit towards the positive direction, denoted as '+'
- Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
Dreamoon 站在数轴上的位置 0 处。Drazil 通过 Wi-Fi 向 Dreamoon 的智能手机发送一系列指令,Dreamoon 随后执行这些指令。
每条指令属于以下两种类型之一:
- 向正方向移动 1 个单位,记为
'+'; - 向负方向移动 1 个单位,记为
'-'。
但由于 Wi-Fi 信号极差,Dreamoon 的智能手机报告称其中部分指令无法被识别;同时 Dreamoon 也知道,即使某些指令被成功识别,它们也可能是错误的。因此,Dreamoon 决定:对所有被识别的指令均照常执行;而对所有未被识别的指令,则抛一枚均匀硬币来决定其执行方式(即以相等的概率 0.5 向正方向或负方向移动 1 个单位)。
现给出 Drazil 发送的原始指令序列,以及 Dreamoon 实际接收到的指令序列。求 Dreamoon 最终所处位置恰好等于 Drazil 原始指令序列所对应最终位置的概率。
输入格式
The first line contains a string _s_1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string _s_2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
第一行包含一个字符串 s1 —— Drazil 发送给 Dreamoon 的指令,该字符串仅由字符集 {′+′,′−′} 中的字符组成。
第二行包含一个字符串 s2 —— Dreamoon 的智能手机所识别的指令,该字符串仅由字符集 {′+′,′−′,′?′} 中的字符组成。其中,'?' 表示无法识别的指令。
两个字符串的长度相等,且均不超过 10。
输出格式
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.
输出一个对应概率的实数。只要答案的相对误差或绝对误差不超过 10−9,即视为正确。
输入输出样例
输入#1
++-+- +-+-+
输出#1
1.000000000000
输入#2
+-+- +-??
输出#2
0.500000000000
输入#3
+++ ??-
输出#3
0.000000000000
说明/提示
For the first sample, both _s_1 and _s_2 will lead Dreamoon to finish at the same position + 1.
For the second sample, _s_1 will lead Dreamoon to finish at position 0, while there are four possibilites for _s_2: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, _s_2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0.
对于第一个样例,s1 和 s2 均会使 Dreamoon 最终停在相同的位置 +1。
对于第二个样例,s1 会使 Dreamoon 最终停在位置 0;而 s2 有四种可能:{"+-++", "+-+-", "+--+", "+---"},对应的最终位置分别为 {+2, 0, 0, −2}。因此,共有 4 种等概率情况,其中 2 种情况能到达正确位置,故最终停在正确位置的概率为 0.5。
对于第三个样例,s2 只能使我们最终停在位置 {+1, −1, −3},因此最终停在正确位置 +3 的概率为 0。
输入解题思路,AI测评打分。不知道怎么写?