2009-12-01から1ヶ月間の記事一覧

SRM 404 DIV2 Level.2

ぐだぐたになったけどシステムテストパスしたからおk。 public class RevealTriangle { public int getAns(int a, int b) { int ret = 0; for (int i = 0; i < 10; i++) { if (a == (b + i) % 10) { ret = i; break; } } return ret; } public String[] cal…

SRM414 DIV2 Level.1

ちょっと時間かかった。 public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First; public U Second; } public class RestaurantManager { public int allocateTables(int[] t</t,>…

SRM397 DIV2 Level.1

適当に解いたらタイムアウト。 一度試したパターンは飛ばすように書き換えたら普通に通った。 public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First; public U Second; } p</t,>…

SRM397 DIV2 Level.1

今日も練習。 簡単。 public class BreakingTheCode { public String decodingEncoding(String code, String message) { String ret = ""; bool isDigit = true; for (int i = 0; i < message.Length; i++) { if (message[i] >= 'a' && message[i] <= 'z') {…

SRM 416 DIV2 Level.1

長いな・・・。 もっとスマートに書けるはず。 public class MostCommonLetters { public String listMostCommon(String[] text) { Dictionary<char, int> dic = new Dictionary<char, int>(); foreach (String s in text) { foreach (Char c in s) { if (c != ' ') { if (dic.Cont</char,></char,>…

C#でC++のstd::pair

C#

What is C# analog of C++ std::pair?(Stack Overflow)より public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First { get; set; } public U Second { get; set; } }; ふむふ</t,>…

SRM 451 DIV2 Level.2

問題文を理解するのに時間がかかってしまった。 感覚で英語読んで、読み飛ばしとかしてるからこうなるんだよな・・・。 using System; using System.Collections.Generic; using System.Text; public class BoredPhilosophers { public int[] simulate(Strin…

SRM 451 DIV2 Level.1

簡単。 using System; using System.Collections.Generic; using System.Text; public class ReverseMagicalSource { public int find(int source, int A) { int ans = 0; int tmp = 1; while (ans <= A) { ans += source * tmp; tmp *= 10; } return ans; }…

SRM420 DIV2 Level.2

パッと見てBFSだとわかるし、これぐらいの問題はすぐに解けないとだめだよな・・・。 結構時間かかってしまった。 using System; using System.Collections.Generic; using System.Text; public class Point { public int X; public int Y; public int D; pu…

SRM417 DIV2 Level.1

今日も練習。 Revese(Reverse(x) + Revese(y)) これを解くだけ。 using System; using System.Collections.Generic; using System.Text; public class ReversedSum { int reverse(int a) { int ret = 0; while (true) { ret += a % 10; if (a >= 10) { ret *…

SRM 453.5 DIV2 Level.1

Stringの配列が与えられて、その中で重複ぬかして単語が何個あるか数える問題。 using System; using System.Collections.Generic; using System.Text; public class ToolsBox { public int countTools(String[] need) { int count = 0; Dictionary<String, int> dic = ne</string,>…