結果
問題 | No.75 回数の期待値の問題 |
ユーザー |
![]() |
提出日時 | 2024-10-10 22:30:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 504 ms / 5,000 ms |
コード長 | 2,406 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 107,520 KB |
実行使用メモリ | 22,272 KB |
最終ジャッジ日時 | 2024-10-10 22:30:12 |
合計ジャッジ時間 | 3,836 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("1"); //6 //サイコロを6回は振らないとちょうど1は出ないとみなせる。 } else if (InputPattern == "Input2") { WillReturn.Add("2"); //6 //1/6の確率で2を出す試行と考えれば6回も振ればちょうど2になるとみなせる。 //もし最初に1が出てしまったとしても、 //次に1/6の確率で1を出せばよいだけなので状況はなんら変わりない。 } else if (InputPattern == "Input3") { WillReturn.Add("3"); //6 } else if (InputPattern == "Input4") { WillReturn.Add("7"); //9.94315 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } //確率の下限 const decimal KakurituKagen = 0.000000001M; static void Main() { List<string> InputList = GetInputList(); int K = int.Parse(InputList[0]); //状態遷移する確率[ダイスの目の和]なDP表 decimal[] PrevDP = new decimal[K]; PrevDP[0] = 1M; decimal Kitaiti = 0M; for (int DiceCnt = 1; ; DiceCnt++) { if (Array.TrueForAll(PrevDP, X => X < KakurituKagen)) break; decimal[] CurrDP = new decimal[K]; for (int I = 0; I <= PrevDP.GetUpperBound(0); I++) { if (PrevDP[I] == 0M) continue; for (int DiceNum = 1; DiceNum <= 6; DiceNum++) { int NewInd = I + DiceNum; if (NewInd == K) { Kitaiti += DiceCnt * PrevDP[I] / 6M; } else { if (NewInd > K) NewInd = 0; //確率の乗法定理と加法定理でDP表を更新 CurrDP[NewInd] += PrevDP[I] / 6M; } } } PrevDP = CurrDP; } Console.WriteLine(Kitaiti); } }