using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); 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 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 AJyunretu = DeriveJyunretu(AArr); List 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 SelectedIndList; } //深さ優先探索で順列を列挙 static List DeriveJyunretu(int[] pArr) { var WillReturn = new List(); var stk = new Stack(); JyoutaiDef WillPush; WillPush.SelectedIndList = new List(); 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(Popped.SelectedIndList); WillPush.SelectedIndList.Add(I); stk.Push(WillPush); } } return WillReturn; } }