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 1"); WillReturn.Add("1 2"); WillReturn.Add("2 3"); //3 //袋Aには白い碁石が2個、黒い碁石が1個入っている。 //袋Bには白い碁石が1個、黒い碁石が2個入っている。 //例えば、袋Aから袋Bに移した2個の碁石が共に白い碁石であり、 //次に、袋Bから袋Aに移した3個の碁石がすべて白い碁石であれば、 //最終的に袋Aには最多で3個の白い碁石がある。 } else if (InputPattern == "Input2") { WillReturn.Add("2 0"); WillReturn.Add("0 3"); WillReturn.Add("2 1"); //1 //最初に袋Aから袋Bに移した2個の碁石はかならず白い碁石である。 //次に、袋Bから袋Aに移した1個の碁石が白い碁石であれば、 //最終的に袋Aには最多で1個の白い碁石がある。 } else if (InputPattern == "Input3") { WillReturn.Add("3 0"); WillReturn.Add("2 3"); WillReturn.Add("0 5"); //5 //最初に、袋Aから袋Bに0個碁石を移す。(つまり碁石の数は動かない。) //次に、袋Bから袋Aに移した5個の碁石が白い碁石が2個、黒い碁石が3個であるので、 //最終的に袋Aには最多で5個の白い碁石がある。 } else if (InputPattern == "Input4") { WillReturn.Add("43682 82641"); WillReturn.Add("54647 3647"); WillReturn.Add("92674 64591"); //98240 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = { }; Action SplitAct = (pIndY) => wkArr = InputList[pIndY].Split(' ').Select(X => int.Parse(X)).ToArray(); int ACntWhite, ACntBlack; int BCntWhite, BCntBlack; int TakeCntFromA, TakeCntFromB; SplitAct(0); ACntWhite = wkArr[0]; ACntBlack = wkArr[1]; SplitAct(1); BCntWhite = wkArr[0]; BCntBlack = wkArr[1]; SplitAct(2); TakeCntFromA = wkArr[0]; TakeCntFromB = wkArr[1]; Action DebugPrintAct = () => { Console.WriteLine(new string('■', 20)); Console.WriteLine("袋Aの白={0}、黒={1}。袋Bの白={2}、黒={3}", ACntWhite, ACntBlack, BCntWhite, BCntBlack); }; //DebugPrintAct(); //Aの袋からBの袋への移動 if (TakeCntFromA <= ACntBlack) { ACntBlack -= TakeCntFromA; BCntBlack += TakeCntFromA; } else { int FirstMoveCnt = ACntBlack; ACntBlack = 0; BCntBlack += FirstMoveCnt; int SecondMoveCnt = TakeCntFromA - FirstMoveCnt; ACntWhite -= SecondMoveCnt; BCntWhite += SecondMoveCnt; } //DebugPrintAct(); //Bの袋からAの袋への移動 if (TakeCntFromB <= BCntWhite) { BCntWhite -= TakeCntFromB; ACntWhite += TakeCntFromB; } else { int FirstMoveCnt = BCntWhite; BCntWhite = 0; ACntWhite += FirstMoveCnt; int SecondMoveCnt = TakeCntFromB - FirstMoveCnt; BCntBlack -= SecondMoveCnt; ACntBlack += SecondMoveCnt; } //DebugPrintAct(); Console.WriteLine(ACntWhite); } }