103192: [Atcoder]ABC319 C - False Hope

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

Description

Score : $300$ points

Problem Statement

There is a $3\times3$ grid with numbers between $1$ and $9$, inclusive, written in each square. The square at the $i$-th row from the top and $j$-th column from the left $(1\leq i\leq3,1\leq j\leq3)$ contains the number $c _ {i,j}$.

The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally. More precisely, it is guaranteed that $c _ {i,j}$ satisfies all of the following conditions.

  • $c _ {i,1}=c _ {i,2}=c _ {i,3}$ does not hold for any $1\leq i\leq3$.
  • $c _ {1,j}=c _ {2,j}=c _ {3,j}$ does not hold for any $1\leq j\leq3$.
  • $c _ {1,1}=c _ {2,2}=c _ {3,3}$ does not hold.
  • $c _ {3,1}=c _ {2,2}=c _ {1,3}$ does not hold.

Takahashi will see the numbers written in each cell in random order. He will get disappointed when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.

  • The first two squares he sees contain the same number, but the last square contains a different number.

Find the probability that Takahashi sees the numbers in all the squares without getting disappointed.

Constraints

  • $c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)$
  • $c _ {i,1}=c _ {i,2}=c _ {i,3}$ does not hold for any $1\leq i\leq3$.
  • $c _ {1,j}=c _ {2,j}=c _ {3,j}$ does not hold for any $1\leq j\leq3$.
  • $c _ {1,1}=c _ {2,2}=c _ {3,3}$ does not hold.
  • $c _ {3,1}=c _ {2,2}=c _ {1,3}$ does not hold.

Input

The input is given from Standard Input in the following format:

$c _ {1,1}$ $c _ {1,2}$ $c _ {1,3}$
$c _ {2,1}$ $c _ {2,2}$ $c _ {2,3}$
$c _ {3,1}$ $c _ {3,2}$ $c _ {3,3}$

Output

Print one line containing the probability that Takahashi sees the numbers in all the squares without getting disappointed. Your answer will be considered correct if the absolute error from the true value is at most $10 ^ {-8}$.


Sample Input 1

3 1 9
2 5 6
2 7 1

Sample Output 1

0.666666666666666666666666666667

For example, if Takahashi sees $c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3$ in this order, he will get disappointed.

On the other hand, if Takahashi sees $c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3}$ in this order, he will see all numbers without getting disappointed.

The probability that Takahashi sees all the numbers without getting disappointed is $\dfrac 23$. Your answer will be considered correct if the absolute error from the true value is at most $10 ^ {-8}$, so outputs such as $0.666666657$ and $0.666666676$ would also be accepted.


Sample Input 2

7 7 6
8 6 8
7 7 6

Sample Output 2

0.004982363315696649029982363316

Sample Input 3

3 6 7
1 9 7
5 7 5

Sample Output 3

0.4

Output

分数:$300$分

问题描述

有一个包含$1$到$9$(包括$1$和$9$)的$3\times3$网格,每个方格中都写了一个数字。从上数第$i$行,从左数第$j$列的方格中包含数字$c _ {i,j}$。

不同的方格中可能写的是相同的数字,但不能在垂直、水平或对角线上连续三个方格中写相同的数字。 更精确地说,保证$c _ {i,j}$满足以下所有条件。

  • 对于任何$1\leq i\leq3$,$c _ {i,1}=c _ {i,2}=c _ {i,3}$不成立。
  • 对于任何$1\leq j\leq3$,$c _ {1,j}=c _ {2,j}=c _ {3,j}$不成立。
  • $c _ {1,1}=c _ {2,2}=c _ {3,3}$不成立。
  • $c _ {3,1}=c _ {2,2}=c _ {1,3}$不成立。

高桥将按照随机顺序看到每个方格中的数字。 当他看到满足以下条件的一条线(垂直、水平或对角线)时,他会感到失望

  • 他看到的前两个方格包含相同的数字,但最后一个方格包含不同的数字。

找到高桥在不感到失望的情况下看到所有方格中数字的概率。

约束

  • $c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)$
  • 对于任何$1\leq i\leq3$,$c _ {i,1}=c _ {i,2}=c _ {i,3}$不成立。
  • 对于任何$1\leq j\leq3$,$c _ {1,j}=c _ {2,j}=c _ {3,j}$不成立。
  • $c _ {1,1}=c _ {2,2}=c _ {3,3}$不成立。
  • $c _ {3,1}=c _ {2,2}=c _ {1,3}$不成立。

输入

输入从标准输入按以下格式给出:

$c _ {1,1}$ $c _ {1,2}$ $c _ {1,3}$
$c _ {2,1}$ $c _ {2,2}$ $c _ {2,3}$
$c _ {3,1}$ $c _ {3,2}$ $c _ {3,3}$

输出

打印一行表示高桥在不感到失望的情况下看到所有方格中数字的概率。 如果与真实值的绝对误差不超过$10 ^ {-8}$,则答案被认为是正确的。


样例输入 1

3 1 9
2 5 6
2 7 1

样例输出 1

0.666666666666666666666666666667

例如,如果高桥按顺序看到$c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3$,他会感到失望。

另一方面,如果高桥按顺序看到$c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3}$,他将在不感到失望的情况下看到所有的数字。

高桥在不感到失望的情况下看到所有数字的概率为$\dfrac 23$。 如果与真实值的绝对误差不超过$10 ^ {-8}$,则答案被认为是正确的,因此输出如$0.666666657$和$0.666666676$也将被视为正确的。


样例输入 2

7 7 6
8 6 8
7 7 6

样例输出 2

0.004982363315696649029982363316

样例输入 3

3 6 7
1 9 7
5 7 5

样例输出 3

0.4

HINT

不知所谓:9个数字已确定位置,逐个揭开来,揭开的时候如果发现一条线上3个数,前两个已知的相同,但第三个却不一样就不好,计算好的概率?

加入题单

上一题 下一题 算法标签: