101933: [AtCoder]ABC193 D - Poker

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

We have $9K$ cards. For each $i = 1, 2, \dots, 9$, there are $K$ cards with $i$ written on it.
We randomly shuffled these cards and handed out five cards - four face up and one face down - to each of Takahashi and Aoki.
You are given a string $S$ representing the cards handed out to Takahashi and a string $T$ representing the cards handed out to Aoki.
$S$ and $T$ are strings of five characters each. Each of the first four characters of each string is 1, 2, $\dots$, or 9, representing the number written on the face-up card. The last character of each string is #, representing that the card is face down.
Let us define the score of a five-card hand as $\displaystyle \sum_{i=1}^9 i \times 10^{c_i}$, where $c_i$ is the number of cards with $i$ written on them.
Takahashi wins when the score of Takahashi's hand is higher than that of Aoki's hand.
Find the probability that Takahashi wins.

Constraints

  • $2 ≤ K ≤ 10^5$
  • $|S| = |T| = 5$
  • The first through fourth characters of each of $S$ and $T$ are 1, 2, $\dots$, or 9.
  • Each of the digit 1, 2, $\dots$, and 9 appears at most $K$ times in total in $S$ and $T$.
  • The fifth character of each of $S$ and $T$ is #.

Input

Input is given from Standard Input in the following format:

$K$
$S$
$T$

Output

Print the probability that Takahashi wins, as a decimal. Your answer will be judged as correct when its absolute or relative error from our answer is at most $10^{-5}$.


Sample Input 1

2
1144#
2233#

Sample Output 1

0.4444444444444444

For example, if Takahashi's hand is 11449 and Aoki's hand is 22338, Takahashi's score is $100+2+3+400+5+6+7+8+90=621$ and Aoki's score is $1+200+300+4+5+6+7+80+9=612$, resulting in Takahashi's win.
Takahashi wins when the number on his face-down card is greater than that of Aoki's face-down card, so Takahashi will win with probability $\frac49$.


Sample Input 2

2
9988#
1122#

Sample Output 2

1.0

Sample Input 3

6
1122#
2228#

Sample Output 3

0.001932367149758454

Takahashi wins only when Takahashi's hand is 11222 and Aoki's hand is 22281, with probability $\frac2{1035}$.


Sample Input 4

100000
3226#
3597#

Sample Output 4

0.6296297942426154

Input

题意翻译

### 题意: 有 $9K$ 张卡片,每张卡片上写有 $1,2,\dots,9$ 中的一个数。这些卡片被随机洗牌,然后将其中 $4K$ 张正面朝上,$K$ 张背面朝上的卡片分别发给高桥和青木。高桥获得的卡片用字符串 $S$ 表示,青木获得的卡片用字符串 $T$ 表示。 字符串 $S$ 和 $T$ 是长度为 $5K$ 的字符串,其中前 $4K$ 个字符是 $1,2,\dots,9$ 中的某一个数字,表示正面朝上的卡片上的数字。接下来的 $1K$ 个字符是 #,表示背面朝上的卡片。定义一组牌的得分为其中包含 $i$ 张数字 $i$ 的牌的数量乘以 $10^i$ 的和,即: $$ \sum_{i=1}^9 i\times 10^{c_i}, $$ 其中 $c_i$ 是字符串 $S$ 或 $T$ 中数字 $i$ 出现的次数。如果高桥的得分比青木高,则高桥获胜。请计算高桥获胜的概率。

加入题单

上一题 下一题 算法标签: