結果

問題 No.75 回数の期待値の問題
ユーザー cielciel
提出日時 2014-11-24 18:20:20
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-30 22:43:31
合計ジャッジ時間 12,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
7,808 KB
testcase_01 AC 22 ms
7,744 KB
testcase_02 AC 22 ms
7,676 KB
testcase_03 AC 26 ms
7,840 KB
testcase_04 AC 23 ms
7,676 KB
testcase_05 AC 23 ms
7,648 KB
testcase_06 AC 25 ms
7,752 KB
testcase_07 AC 27 ms
7,640 KB
testcase_08 AC 30 ms
7,644 KB
testcase_09 AC 32 ms
7,760 KB
testcase_10 AC 34 ms
7,820 KB
testcase_11 AC 38 ms
7,864 KB
testcase_12 AC 42 ms
7,660 KB
testcase_13 AC 47 ms
7,676 KB
testcase_14 AC 49 ms
7,844 KB
testcase_15 AC 80 ms
7,676 KB
testcase_16 AC 3,674 ms
8,152 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
#derived from checkio expected-dice

from fractions import Fraction
def gauss(a):
	if not a or len(a)==0: return None
	n=len(a)
	for i in range(n):
		if a[i][i]==0:
			for j in range(i+1,n):
				if a[j][i]!=0:
					for k in range(i,n+1): a[i][k]+=a[j][k]
					break
			else:
				return None
		for j in range(n):
			if i!=j:
				r = Fraction(a[j][i],a[i][i])
				for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r
	for i in range(n):
		x=Fraction(a[i][i],1)
		for j in range(len(a[i])):
			a[i][j] /= x
	return a

def expected(n, s, t): #, b):
	#perform probably-dice
	a=[0]*(s*(n+1)+1)
	for i in range(1,s+1):
		a[i+s]=Fraction(1,s)**n
	for e in range(n-1):
		for i in reversed(range(0,s*n+1)):
			a[i+s]=sum(a[i:i+s])
	l = t+1
	A = [[int(i==j) for i in range(l)]+[int(j!=t)] for j in range(l)]
	for start in range(l):
		if start != t:
			for roll in range(n,s*n+1):
				end = roll + start
				#end = (end + b[end%l])%l
				if end>=l: end=0
				A[start][end] -= a[roll+s]
	return float(gauss(A)[0][-1])

if __name__ == '__main__':
	import sys
	if sys.version_info[0]>=3: raw_input=input
	N=int(raw_input())
	print(expected(1,6,N))
0