private void WriteImpossible(int R, int C, int M) { m_io.WriteCase(Impossible); //Console.WriteLine("{0}, {1}, {2} ({3})", R, C, M, R*C-M); //for (int r = 0; r < R; r++) //{ // for (int c = 0; c < C; c++) // { // Console.Write('*'); // } // Console.WriteLine(); //} }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int answer1 = m_io.ReadInt(); var firstRowSet = new HashSet <int>(); for (int r = 1; r < 5; r++) { for (int c = 1; c < 5; c++) { int card = m_io.ReadInt(); if (r == answer1) { firstRowSet.Add(card); } } } int answer2 = m_io.ReadInt(); var answers = new HashSet <int>(); for (int r = 1; r < 5; r++) { for (int c = 1; c < 5; c++) { int card = m_io.ReadInt(); if (r == answer2 && firstRowSet.Contains(card)) { answers.Add(card); } } } if (answers.Count == 0) { m_io.WriteCase("Volunteer cheated!"); } else if (answers.Count == 1) { m_io.WriteCase(answers.First()); } else { m_io.WriteCase("Bad magician!"); } } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { double C_FarmCost = m_io.ReadDouble(); double F_FarmBonus = m_io.ReadDouble(); double X_Goal = m_io.ReadDouble(); double currentRate = 2.0; //c/s double currentTime = 0.0; //s double currentCookies = 0.0; //c for (; ;) { double timeToWinWithCurrentFarms = (X_Goal - currentCookies) / currentRate; double timeUntilAffordNextFarm = (C_FarmCost - currentCookies) / currentRate; double timeToWinWithAnotherFarm = timeUntilAffordNextFarm + X_Goal / (currentRate + F_FarmBonus); if (timeToWinWithCurrentFarms < timeToWinWithAnotherFarm) { m_io.WriteCase(currentTime + timeToWinWithCurrentFarms); break; } else { currentTime += timeUntilAffordNextFarm; currentCookies = 0.0; currentRate += F_FarmBonus; } } } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int N = m_io.ReadInt(); int[][] parents = new int[N][]; for (int i = 0; i < N; i++) { int numParents = m_io.ReadInt(); parents[i] = Enumerable.Range(i, numParents).Select(j => m_io.ReadInt()).ToArray(); } bool hasDiamond = false; for (int i = 0; !hasDiamond && i < N; i++) { HashSet <int> ancestors = new HashSet <int>(); for (int par = 0; !hasDiamond && par < parents[i].Length; par++) { int current = parents[i][par]; foreach (int ancest in GetAllAncest(current, parents)) { if (!ancestors.Add(ancest)) { hasDiamond = true; break; } } } } m_io.WriteCase(hasDiamond ? "Yes" : "No"); } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int N = m_io.ReadInt(); List <Tuple <char, int> > actions = new List <Tuple <char, int> >(N); for (int n = 0; n < N; n++) { actions.Add(new Tuple <char, int>(m_io.ReadWord()[0], m_io.ReadInt())); } int otime = 0; int btime = 0; int opos = 1; int bpos = 1; foreach (var action in actions) { if (action.Item1 == 'O') { UpdateRobot(action.Item2, ref opos, ref otime, bpos, btime); } else { UpdateRobot(action.Item2, ref bpos, ref btime, opos, otime); } } m_io.WriteCase(Math.Max(otime, btime)); } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int N = m_io.ReadInt(); int sum = 0; int xor = 0; List <int> candy = new List <int>(N); for (int n = 0; n < N; n++) { int value = m_io.ReadInt(); candy.Add(value); sum += value; if (n == 0) { xor = value; } else { xor ^= value; } } int best = -1; for (int i = 0; i < N; i++) { if (candy[i] == (xor ^ candy[i]) && sum - candy[i] > best) { best = sum - candy[i]; } } if (best == -1) { m_io.WriteCase("NO"); } else { m_io.WriteCase(best); } } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int N = m_io.ReadInt(); int countWrong = 0; for (int n = 0; n < N; n++) { if (m_io.ReadInt() != n + 1) { countWrong++; } } m_io.WriteCase(String.Format("{0:0.000000}", countWrong)); } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int numBoxes = m_io.ReadInt(); int numToys = m_io.ReadInt(); var boxes = Enumerable.Range(0, numBoxes).Select(i => new Thing { Count = m_io.ReadLong(), Type = m_io.ReadLong() }).ToArray(); var toys = Enumerable.Range(0, numToys).Select(i => new Thing { Count = m_io.ReadLong(), Type = m_io.ReadLong() }).ToArray(); m_io.WriteCase(Solve(0, 0, boxes, toys, 0)); } }
private void Go() { int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int N_Blocks = m_io.ReadInt(); double[] Naomi = new double[N_Blocks]; double[] Ken = new double[N_Blocks]; for (int i = 0; i < N_Blocks; i++) { Naomi[i] = m_io.ReadDouble(); } for (int i = 0; i < N_Blocks; i++) { Ken[i] = m_io.ReadDouble(); } Array.Sort(Naomi); Array.Sort(Ken); //deceptive: pop lowest until int kSmallest = 0; int nSmallest = 0; int kLargest = N_Blocks - 1; int nLargest = N_Blocks - 1; int normalScore = 0; //Normal for (int i = 0; i < N_Blocks; i++) { if (Naomi[nLargest] > Ken[kLargest]) { nLargest--; kSmallest++; normalScore++; } else { nLargest--; kLargest--; } } kSmallest = 0; nSmallest = 0; kLargest = N_Blocks - 1; nLargest = N_Blocks - 1; int deceptiveScore = 0; //deceptive for (int i = 0; i < N_Blocks; i++) { if (Naomi[nSmallest] < Ken[kSmallest]) { kLargest--; nSmallest++; } else { nSmallest++; kSmallest++; deceptiveScore++; } } m_io.WriteCase(deceptiveScore + " " + normalScore); } }
private void Go() { Dictionary <char, int> emptyTally = c_baseElements.ToDictionary(e => e, e => 0); int T = m_io.ReadInt(); for (int t = 0; t < T; t++) { int C = m_io.ReadInt(); Dictionary <string, char> combiners = new Dictionary <string, char>(C * 2); for (int c = 0; c < C; c++) { string com = m_io.ReadWord(); combiners.Add(com.Substring(0, 2), com[2]); if (com[1] != com[0]) { combiners.Add(com[1].ToString() + com[0].ToString(), com[2]); } } int D = m_io.ReadInt(); HashSet <string> oposers = new HashSet <string>(); for (int d = 0; d < D; d++) { string opp = m_io.ReadWord(); oposers.Add(opp[0].ToString() + opp[1]); oposers.Add(opp[1].ToString() + opp[0]); } int N = m_io.ReadInt(); string seq = m_io.ReadWord(); Dictionary <char, int> tally = new Dictionary <char, int>(emptyTally); List <char> state = new List <char>(seq.Length); char last = '?'; foreach (char next in seq) { char toAdd = next; char combined; if (combiners.TryGetValue(last.ToString() + next, out combined)) { toAdd = combined; } bool flush = false; string toAddStr = toAdd.ToString(); foreach (string curact in tally.Where(kvp => kvp.Value > 0).Select(kvp => kvp.Key + toAddStr)) { if (oposers.Contains(curact)) { flush = true; break; } } if (flush) { tally = new Dictionary <char, int>(emptyTally); state.Clear(); last = '?'; } else { if (toAdd == next) { tally[toAdd]++; state.Add(toAdd); } else { tally[last]--; state[state.Count - 1] = toAdd; } last = toAdd; } } m_io.WriteCase("[" + String.Join(", ", state) + "]"); } }