結果

問題 No.58 イカサマなサイコロ
ユーザー gigurururugigurururu
提出日時 2014-11-05 20:28:32
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,402 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 6,600 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2023-08-29 00:41:09
合計ジャッジ時間 851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,000 KB
testcase_01 AC 12 ms
6,004 KB
testcase_02 AC 12 ms
6,144 KB
testcase_03 AC 11 ms
6,044 KB
testcase_04 AC 11 ms
6,088 KB
testcase_05 AC 12 ms
6,056 KB
testcase_06 AC 12 ms
6,064 KB
testcase_07 AC 12 ms
6,000 KB
testcase_08 AC 12 ms
6,068 KB
testcase_09 AC 12 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# 前回までの目の合計ごとのパターン数 pr
# 今回振るさいころの目 rolls
# 今回振った後の目の合計ごとのパターン数 戻り値
# pr      0 1 1 1 1 1 1 
# rolls
# 1         0 1 1 1 1 1 1
# 2           0 1 1 1 1 1 1
# 3             0 1 1 1 1 1 1
# 4               0 1 1 1 1 1 1
# 5                 0 1 1 1 1 1 1
# 6                   0 1 1 1 1 1 1
# ret     0 1 2 3 4 5 6 6 5 4 3 2 1

# pr      0 1 1 1 1 1 1 
# rolls
# 4               0 1 1 1 1 1 1
# 5                 0 1 1 1 1 1 1
# 6                   0 1 1 1 1 1 1
# 4               0 1 1 1 1 1 1
# 5                 0 1 1 1 1 1 1
# 6                   0 1 1 1 1 1 1
# ret     0 0 0 0 0 2 4 6 6 6 6 4 2
def dice(pr,rolls):
    padding=[0]*len(rolls)
    return map(sum,zip(*[padding[:i]+pr+padding[i:] for i in rolls]))

n=input()
k=input()
jiro=[1]#さいころを0回振ったときに出る目(index)の合計のパターン数・・・0が1回のみ
for _ in range(n):
    jiro=dice(jiro,range(1,7))

taro=[1]
for _ in range(n-k):
    taro=dice(taro,range(1,7))

for _ in range(k):
    taro=dice(taro,range(4,7)*2)

v=0
jiro_sum=[0]#目の合計がindex以下になるパターン数
for i in jiro:
    v+=i
    jiro_sum.append(v)

print float(sum([x*y for x,y in zip(jiro_sum,taro)]))/6**(2*n)#太郎が勝つパターン数/全パターン数
0