結果

問題 No.133 カードゲーム
ユーザー 明智重蔵明智重蔵
提出日時 2016-02-09 05:59:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 3,229 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 108,524 KB
実行使用メモリ 24,108 KB
最終ジャッジ日時 2023-09-07 09:24:22
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
23,752 KB
testcase_01 AC 72 ms
21,804 KB
testcase_02 AC 72 ms
22,036 KB
testcase_03 AC 69 ms
21,940 KB
testcase_04 AC 71 ms
21,896 KB
testcase_05 AC 71 ms
21,812 KB
testcase_06 AC 71 ms
21,788 KB
testcase_07 AC 73 ms
23,932 KB
testcase_08 AC 72 ms
23,804 KB
testcase_09 AC 71 ms
21,928 KB
testcase_10 AC 71 ms
19,944 KB
testcase_11 AC 72 ms
21,988 KB
testcase_12 AC 73 ms
21,940 KB
testcase_13 AC 72 ms
19,976 KB
testcase_14 AC 72 ms
24,108 KB
testcase_15 AC 72 ms
21,884 KB
testcase_16 AC 73 ms
21,892 KB
testcase_17 AC 73 ms
21,896 KB
testcase_18 AC 73 ms
21,992 KB
testcase_19 AC 72 ms
21,968 KB
testcase_20 AC 73 ms
21,932 KB
testcase_21 AC 73 ms
23,952 KB
testcase_22 AC 72 ms
21,896 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 = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("2 4");
            WillReturn.Add("1 3");
            //0.5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            WillReturn.Add("3 4");
            WillReturn.Add("1 2");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1");
            WillReturn.Add("1");
            WillReturn.Add("2");
            //0
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("3");
            WillReturn.Add("6 2 3");
            WillReturn.Add("1 5 4");
            //0.666667
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        int[] BArr = InputList[2].Split(' ').Select(X => int.Parse(X)).ToArray();

        List<int[]> AJyunretu = DeriveJyunretu(AArr);
        List<int[]> BJyunretu = DeriveJyunretu(BArr);

        decimal TotalPatternCnt = AJyunretu.Count * BJyunretu.Count;
        decimal WinAPatternCnt = 0;

        foreach (int[] EachA in AJyunretu) {
            foreach (int[] EachB in BJyunretu) {
                int WinCnt = 0;
                int LoseCnt = 0;

                for (int I = 0; I <= AArr.GetUpperBound(0); I++) {
                    if (EachA[I] > EachB[I]) WinCnt++;
                    if (EachA[I] < EachB[I]) LoseCnt++;
                }
                if (WinCnt > LoseCnt) WinAPatternCnt++;
            }
        }
        Console.WriteLine(WinAPatternCnt / TotalPatternCnt);
    }

    struct JyoutaiDef
    {
        internal List<int> SelectedIndList;
    }

    //深さ優先探索で順列を列挙
    static List<int[]> DeriveJyunretu(int[] pArr)
    {
        var WillReturn = new List<int[]>();

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.SelectedIndList = new List<int>();
        stk.Push(WillPush);

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

            //クリア判定
            if (Popped.SelectedIndList.Count == pArr.Length) {
                int[] wkArr = new int[pArr.Length];
                for (int I = 0; I <= wkArr.GetUpperBound(0); I++) {
                    wkArr[I] = pArr[Popped.SelectedIndList[I]];
                }
                WillReturn.Add(wkArr);
                continue;
            }

            for (int I = 0; I <= pArr.GetUpperBound(0); I++) {
                if (Popped.SelectedIndList.Contains(I)) continue;

                WillPush.SelectedIndList = new List<int>(Popped.SelectedIndList);
                WillPush.SelectedIndList.Add(I);
                stk.Push(WillPush);
            }
        }
        return WillReturn;
    }
}
0