結果
問題 | No.161 制限ジャンケン |
ユーザー |
![]() |
提出日時 | 2015-08-28 21:52:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 27 ms / 5,000 ms |
コード長 | 2,340 bytes |
コンパイル時間 | 994 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-11-30 04:45:28 |
合計ジャッジ時間 | 2,112 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
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 = "Input5";static List<string> GetInputList(){var WillReturn = new List<string>();if (InputPattern == "Input1") {WillReturn.Add("2 1 1");WillReturn.Add("CCGP");//12}else if (InputPattern == "Input2") {WillReturn.Add("0 0 5");WillReturn.Add("CCCCC");//0}else if (InputPattern == "Input3") {WillReturn.Add("7 6 5");WillReturn.Add("GCPGPCPGGGPCCCGPGP");//50}else {string wkStr;while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);}return WillReturn;}static void Main(){List<string> InputList = GetInputList();int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();int CardCntG = wkArr[0];int CardCntC = wkArr[1];int CardCntP = wkArr[2];char[] SArr = InputList[1].ToCharArray();int AiteCntG = SArr.Count(X => X == 'G');int AiteCntC = SArr.Count(X => X == 'C');int AiteCntP = SArr.Count(X => X == 'P');int Score = 0;//勝てるカードを全て割当Score += ExecWariate(ref CardCntG, ref AiteCntC) * 3;Score += ExecWariate(ref CardCntC, ref AiteCntP) * 3;Score += ExecWariate(ref CardCntP, ref AiteCntG) * 3;//あいこになるカードを全て割当Score += ExecWariate(ref CardCntG, ref AiteCntG);Score += ExecWariate(ref CardCntC, ref AiteCntC);Score += ExecWariate(ref CardCntP, ref AiteCntP);Console.WriteLine(Score);}//貪欲法で、カードを割当し、割当枚数を返すstatic int ExecWariate(ref int pCardCnt, ref int pAiteCnt){int WillReturn;//全て割当可能の場合if (pCardCnt <= pAiteCnt) {WillReturn = pCardCnt;pAiteCnt -= pCardCnt;pCardCnt = 0;return WillReturn;}//一部割当可能の場合WillReturn = pAiteCnt;pCardCnt -= pAiteCnt;pAiteCnt = 0;return WillReturn;}}