結果

問題 No.75 回数の期待値の問題
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-12 13:18:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 551 ms / 5,000 ms
コード長 2,405 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 105,848 KB
実行使用メモリ 26,992 KB
最終ジャッジ日時 2023-09-26 11:38:33
合計ジャッジ時間 5,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
18,680 KB
testcase_01 AC 64 ms
20,828 KB
testcase_02 AC 64 ms
20,908 KB
testcase_03 AC 66 ms
20,660 KB
testcase_04 AC 64 ms
18,796 KB
testcase_05 AC 63 ms
20,708 KB
testcase_06 AC 64 ms
20,776 KB
testcase_07 AC 67 ms
20,828 KB
testcase_08 AC 66 ms
22,844 KB
testcase_09 AC 67 ms
20,788 KB
testcase_10 AC 67 ms
20,740 KB
testcase_11 AC 67 ms
20,752 KB
testcase_12 AC 69 ms
20,928 KB
testcase_13 AC 68 ms
20,792 KB
testcase_14 AC 69 ms
20,880 KB
testcase_15 AC 71 ms
18,672 KB
testcase_16 AC 158 ms
20,836 KB
testcase_17 AC 357 ms
24,984 KB
testcase_18 AC 486 ms
26,992 KB
testcase_19 AC 551 ms
24,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "Input5";

    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);
    }
}
0