結果
| 問題 |
No.75 回数の期待値の問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-24 09:39:02 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,043 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 07:48:20 |
| 合計ジャッジ時間 | 1,041 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
local k = io.read("*n")
k = k + 1
local t = {}
t[1] = 1
for i = 2, k do
t[i] = 0
end
local rem = 1
local e = 0
local cnt = 0
while(0.00001 < rem) do
cnt = cnt + 1
-- GOAL
local tmp = t[k - 1]
if(2 < k) then tmp = tmp + t[k - 2] end
if(3 < k) then tmp = tmp + t[k - 3] end
if(4 < k) then tmp = tmp + t[k - 4] end
if(5 < k) then tmp = tmp + t[k - 5] end
if(6 < k) then tmp = tmp + t[k - 6] end
e = e + cnt * tmp / 6
rem = rem - tmp / 6
-- START
local st = t[k - 1] * 5
if(2 < k) then st = st + t[k - 2] * 4 end
if(3 < k) then st = st + t[k - 3] * 3 end
if(4 < k) then st = st + t[k - 4] * 2 end
if(5 < k) then st = st + t[k - 5] end
st = st / 6
-- MID
for i = k - 1, 2, -1 do
t[i] = t[i - 1]
if(2 < i) then t[i] = t[i] + t[i - 2] end
if(3 < i) then t[i] = t[i] + t[i - 3] end
if(4 < i) then t[i] = t[i] + t[i - 4] end
if(5 < i) then t[i] = t[i] + t[i - 5] end
if(6 < i) then t[i] = t[i] + t[i - 6] end
t[i] = t[i] / 6
end
t[1] = st
end
print(string.format("%.8f", e))