C♯の勉強

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

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

TopCoder SRM598: TPS

public class TPS { static int[] GetDegrees(string[] linked) { var n = linked.Length; var deg = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (linked[i][j] == 'Y') { deg[j]++; } } } return deg; } String[] Shrink…

TopCoder SRM598: FoxAndFencing

public class FoxAndFencing { const string Ciel = "Ciel"; const string Liss = "Liss"; const string Draw = "Draw"; public string WhoCanWin(int mov1, int mov2, int rng1, int rng2, int d) { if (mov1 + rng1 >= d) return Ciel; if (mov1 + d <= mo…

TopCoder SRM598: BinPacking

public class BinPacking { public int minBins(int[] item) { Array.Sort(item); int n = item.Length; bool[] used = new bool[n]; int ans = 0; for (int i = n - 1; i >= 0; i--) { if (used[i]) continue; int target = -1; for (int j = i - 1; j >= 0…

TopCoder SRM598: FoxAndFencingEasy

public class FoxAndFencingEasy { const string Ciel = "Ciel"; const string Liss = "Liss"; const string Draw = "Draw"; public string WhoCanWin(int mov1, int mov2, int d) { if (mov1 >= d) return Ciel; if (mov1 > mov2 * 2) return Ciel; if (mov…

TopCoder SRM598: BinPackingEasy

public class BinPackingEasy { public int minBins(int[] item) { Array.Sort(item); int ans = 0; int n = item.Length; bool[] used = new bool[n]; for (int i = n - 1; i >= 0; i--) { if (used[i]) continue; int target = -1; for (int j = i - 1; j …

TopCoder SRM598: ErasingCharacters

s.Substring(0, i)+s.Substring(i + 2) とするより Remove 使ったほうが楽でした。 public class ErasingCharacters { public string simulate(string s) { for (int i = 0; i < s.Length - 1; i++) { if (s[i] == s[i + 1]) { return simulate(s.Remove(i, …