結果

問題 No.133 カードゲーム
ユーザー aketijyuuzouaketijyuuzou
提出日時 2024-10-10 22:52:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 3,670 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 108,416 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-10-10 22:52:14
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
19,328 KB
testcase_01 AC 32 ms
19,456 KB
testcase_02 AC 33 ms
19,200 KB
testcase_03 AC 32 ms
19,328 KB
testcase_04 AC 32 ms
19,456 KB
testcase_05 AC 33 ms
19,200 KB
testcase_06 AC 31 ms
19,456 KB
testcase_07 AC 32 ms
19,328 KB
testcase_08 AC 33 ms
19,328 KB
testcase_09 AC 33 ms
19,328 KB
testcase_10 AC 33 ms
19,072 KB
testcase_11 AC 33 ms
19,456 KB
testcase_12 AC 32 ms
19,200 KB
testcase_13 AC 32 ms
19,328 KB
testcase_14 AC 32 ms
19,328 KB
testcase_15 AC 33 ms
19,200 KB
testcase_16 AC 32 ms
19,200 KB
testcase_17 AC 33 ms
19,072 KB
testcase_18 AC 33 ms
19,328 KB
testcase_19 AC 33 ms
19,200 KB
testcase_20 AC 33 ms
19,456 KB
testcase_21 AC 33 ms
19,328 KB
testcase_22 AC 34 ms
19,456 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
            //A君に2と4のカードが配られる。B君に1と3のカードが配られる。
            //試合は2試合でA君の出し方が2通り、
            //B君の出し方が2通りなので全部で4通りの結果になる。
            //A君が勝つのはそのうち2通りなので、確率は2/4=0.5である。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            WillReturn.Add("3 4");
            WillReturn.Add("1 2");
            //1
            //どうやってもA君が勝つ
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1");
            WillReturn.Add("1");
            WillReturn.Add("2");
            //0
            //どうやってもA君は勝てない
        }
        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