C♯の勉強

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

2013-10-02から1日間の記事一覧

TopCoder SRM587: ThreeColorabilityEasy

public class ThreeColorabilityEasy { int n, m; int ToIndex(int row, int col) { return row * (m + 1) + col; } List[] ConstrustGraph(string[] cells) { int nodeNum = (n + 1) * (m + 1); var graph = Enumerable.Range(0, nodeNum).Select(_ => new …

TopCoder SRM587: TriangleXor

public class TriangleXor { public int theArea(int W) { double area = 0; // top if (W % 2 == 0) area += W / 4.0; // side double ratio = 0, prevX = 0; for (int i = 1; i <= W; i++) { double x = 1.0 * i * W / (W + i); if (i % 2 == 1) { ratio +…

TopCoder SRM592: LittleElephantAndPermutationDiv1

a1 , .. , an b1 , .. , bn 順列 a,b に対して、N から 1 まで。大きい順に値を配置していくことを考える。 大きい順に配置するため、両方空いている場所に値 i を配置した時点で もう片側に i 以下の値しか入らないので、 magic(A,B) に i が追加される。値…