結果

問題 No.65 回数の期待値の練習
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-12 11:27:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 3,559 ms / 5,000 ms
コード長 2,418 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 107,376 KB
実行使用メモリ 237,712 KB
最終ジャッジ日時 2023-09-26 11:37:36
合計ジャッジ時間 11,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
21,628 KB
testcase_01 AC 67 ms
21,616 KB
testcase_02 AC 67 ms
21,588 KB
testcase_03 AC 67 ms
21,612 KB
testcase_04 AC 68 ms
21,512 KB
testcase_05 AC 67 ms
21,532 KB
testcase_06 AC 68 ms
23,672 KB
testcase_07 AC 68 ms
21,532 KB
testcase_08 AC 68 ms
21,708 KB
testcase_09 AC 69 ms
21,676 KB
testcase_10 AC 73 ms
23,720 KB
testcase_11 AC 78 ms
23,676 KB
testcase_12 AC 92 ms
26,544 KB
testcase_13 AC 116 ms
30,916 KB
testcase_14 AC 165 ms
34,256 KB
testcase_15 AC 262 ms
39,520 KB
testcase_16 AC 461 ms
55,660 KB
testcase_17 AC 885 ms
78,908 KB
testcase_18 AC 1,748 ms
139,164 KB
testcase_19 AC 3,559 ms
237,712 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");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            //1.16667
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3");
            //1.36111
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("7");
            //2.52163
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int K = int.Parse(InputList[0]);

        List<int[]> NumList = ExecDFS(K);

        decimal Kitaiti = 0;

        foreach (int[] EachArr in NumList) {
            decimal Bunbo = 1;
            for (int I = 1; I <= EachArr.Length; I++) Bunbo *= 6;
            decimal Bunsi = 1;

            Kitaiti += EachArr.Length * Bunsi / Bunbo;
        }
        Console.WriteLine(Kitaiti);
    }

    //階乗を求める
    static decimal DeriveKaijyou(int pN)
    {
        decimal WillReturn = 1;
        for (int I = 2; I <= pN; I++) {
            WillReturn *= I;
        }
        return WillReturn;
    }

    struct JyoutaiDef
    {
        internal List<int> NumList;
    }

    //合計がKになるまでの、サイコロの目の組み合わせを列挙
    static List<int[]> ExecDFS(int pK)
    {
        var WillReturn = new List<int[]>();

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        for (int I = 1; I <= 6; I++) {
            WillPush.NumList = new List<int>() { I };
            stk.Push(WillPush);
        }

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();

            //クリア判定
            if (Popped.NumList.Sum() >= pK) {
                WillReturn.Add(Popped.NumList.ToArray());
                continue;
            }

            for (int I = 1; I <= 6; I++) {
                WillPush.NumList = new List<int>(Popped.NumList) { I };
                stk.Push(WillPush);
            }
        }
        return WillReturn;
    }
}
0