結果
| 問題 |
No.133 カードゲーム
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
}
}
aketijyuuzou