C♯の勉強

C♯4.0 で TopCoder の過去問を解きます。

2013-09-12から1日間の記事一覧

TopCoder SRM 586: PiecewiseLinearFunctionDiv2

問題文線形な区間ごとに解があるかを判定する。重解に注意。 public class PiecewiseLinearFunctionDiv2 { public int numberOfSolution(int[] Y, int y) { int n = Y.Length; int ans = Y[0] == y ? 1 : 0; for (int i = 0; i < n - 1; i++) { if (Y[i] < y…

TopCoder SRM 586: TeamsSelection

問題文交互に最も preference が高い選手を選んでいく。 public class TeamsSelection { public string simulate(int[] preference1, int[] preference2) { int n = preference1.Length; var result = Enumerable.Repeat(' ', n).ToArray(); for (int i = 0;…

TopCoder SRM 587: InsertZ

問題文やるだけ。 goal から 'z' を除いたものが init と等しいかどうかを判定する。 public class InsertZ { public string canTransform(string init, string goal) { return goal.Replace("z", "") == init ? "Yes" : "No"; } }

TopCoder SRM 590: XorCards

public class XorCards { public long NumberOfSolution(int[,] matrix) { int n = matrix.GetLength(0); int m = matrix.GetLength(1); bool[] used = new bool[n]; for (int i = 0; i < m; i++) { int target = -1; for (int j = 0; j < n; j++) { if (!us…

TopCoder SRM 588: GameInDarknessDiv1

問題文 解法 ###.### ###.### ###.### ...x... ####### 上のような「最大の深さが3以上の子ノードが3以上あるような地点 x」が存在して、 Bob が Alice より 2ターンか、それ以上早く先にその地点にたどり着くことができれば Bob の勝ち、それ以外は Alice…