公式

D - 456 解説 by en_translator


If we distinguish the faces of the dice, there are \(6\times 6\times 6=216\) possible outcomes. Examine each of the \(216\) outcomes and check if they are \(4,5\), and \(6\).

To check it, we can either examine all six combinations of the outcome, or determine the equality as sets, if sorting makes it \((4,5,6)\), or if their product is \(120\).

Beware of how to print decimals depending on your language to use.

Sample code (C++)

#include<bits/stdc++.h>
using namespace std;

int main(){
  int a[3][6];
  for(int i=0; i<3; i++){
    for(int j=0; j<6; j++) cin >> a[i][j];
  }

  int ans = 0;
  for(int i=0; i<6; i++){
    for(int j=0; j<6; j++){
      for(int k=0; k<6; k++){
        if(   (a[0][i]==4 && a[1][j]==5 && a[2][k]==6)
           || (a[0][i]==4 && a[1][j]==6 && a[2][k]==5)
           || (a[0][i]==5 && a[1][j]==4 && a[2][k]==6)
           || (a[0][i]==5 && a[1][j]==6 && a[2][k]==4)
           || (a[0][i]==6 && a[1][j]==4 && a[2][k]==5)
           || (a[0][i]==6 && a[1][j]==5 && a[2][k]==4)){
          ans++;
        }
      }
    }
  }
  printf("%.10f\n", ans/216.0);
}

Sample code (Python)

A = []
for _ in range(3):
  Ai = list(map(int, input().split()))
  A.append(Ai)

ans = 0
for x in A[0]:
  for y in A[1]:
    for z in A[2]:
      if sorted([x, y, z]) == [4, 5, 6]:
        ans += 1

print(f"{ans/216: .10f}")

投稿日時:
最終更新: