

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
1,2,3,4,5,6 の 6 種類の目が出るサイコロを 2 つ振ったときに、次の 2 つの条件の少なくとも一方を満たす確率を求めてください。
- 2 つの出目の合計が X 以上である。
- 2 つの出目の差の絶対値が Y 以上である。
ここで、どちらのサイコロについても 6 種類のどの目が出るかは同様に確からしく、それぞれのサイコロの出目は独立であるとします。
制約
- 2\leq X\leq13
- 0\leq Y\leq6
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
2 つのサイコロの出目が 2 つの条件の少なくとも一方を満たす確率を出力せよ。 出力された値と真の値との絶対誤差が 10 ^ {-9} 以下のとき、正答と判定される。
入力例 1
9 3
出力例 1
0.555555555555555555555555555555
2 つのサイコロの出目がそれぞれ x と y であることを (x,y) で表すことにすると、それぞれの条件を満たすのは次の場合です。
- 2 つのサイコロの出目の和が 9 以上になるのは、(3,6),(4,5),(4,6),(5,4),(5,5),(5,6),(6,3),(6,4),(6,5),(6,6) のとき
- 2 つのサイコロの出目の差が 3 以上になるのは、(1,4),(1,5),(1,6),(2,5),(2,6),(3,6),(4,1),(5,1),(5,2),(6,1),(6,2),(6,3) のとき
これらの条件の少なくとも一方を満たすのは (1,4),(1,5),(1,6),(2,5),(2,6),(3,6),(4,1),(4,5),(4,6),(5,1),(5,2),(5,4),(5,5),(5,6),(6,1),(6,2),(6,3),(6,4),(6,5),(6,6) の 20 通りのいずれかのときです。
よって、求める答えは \dfrac{20}{36}=\dfrac59=0.5555555555\ldots です。
絶対誤差が 10 ^ {-9} 以下のとき正答と判定されるので、0.5555555565
や 0.55555555456789
などと出力しても正解となります。
入力例 2
13 6
出力例 2
0
2 つのサイコロの出目の和が 13 以上になることも、差が 6 以上になることもありません。
よって、求める答えは 0 です。
入力例 3
10 3
出力例 3
0.5
Score : 250 points
Problem Statement
Two dice, each with six faces 1,2,3,4,5,6, are rolled. Find the probability that at least one of the following two conditions holds:
- The sum of the two outcomes is at least X.
- The absolute difference of the two outcomes is at least Y.
Each face of each die is equally likely, and the two dice are independent.
Constraints
- 2 \le X \le 13
- 0 \le Y \le 6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y
Output
Output the probability that the two outcomes satisfy at least one of the two conditions. Your answer is accepted if its absolute error from the true value is at most 10^{-9}.
Sample Input 1
9 3
Sample Output 1
0.555555555555555555555555555555
Let (x,y) denote the event that the dice show x and y.
- The sum is at least 9 for (3,6),(4,5),(4,6),(5,4),(5,5),(5,6),(6,3),(6,4),(6,5),(6,6).
- The difference is at least 3 for (1,4),(1,5),(1,6),(2,5),(2,6),(3,6),(4,1),(5,1),(5,2),(6,1),(6,2),(6,3).
At least one of these conditions holds for the following 20 pairs: (1,4),(1,5),(1,6),(2,5),(2,6),(3,6),(4,1),(4,5),(4,6),(5,1),(5,2),(5,4),(5,5),(5,6),(6,1),(6,2),(6,3),(6,4),(6,5),(6,6).
Thus, the answer is \dfrac{20}{36}=\dfrac59=0.5555555555\ldots.
Because an absolute error of at most 10^{-9} is allowed, outputs such as 0.5555555565
or 0.55555555456789
are accepted.
Sample Input 2
13 6
Sample Output 2
0
Neither the sum of two dice can be 13 or greater, nor can their difference be 6 or greater.
Thus, the answer is 0.
Sample Input 3
10 3
Sample Output 3
0.5