C#

SRM 462 DIV2

Easy::Archery 問題文を読み違えて時間かかりました。何故かradiusを直径のことだと勘違い・・・。 public class Archery { public double expectedPoints(int N, int[] ringPoints) { double[] array = new double[N + 1]; double sum = 0.0; double r = 0.…

SRM460 DIV2

Easy::TheQuestionsAndAnswersDivTwo public class TheQuestionsAndAnswersDivTwo { public int find(string[] questions) { List<string> q = new List<string>(); foreach (String s in questions) { if (q.Contains(s)) { continue; } else { q.Add(s); } } return (int)M</string></string>…

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,>…

SRM391 DIV2 Level.2

文字列が与えられて、その中の文字を一意に置き換えたら同じになる組み合わせが何個あるか求めろという問題。 C#がよくわかってないんで大分適当。システムテストにパスしたからまあいいんだけどさー。 if (list[i].Equals(list[j]))って書き方は駄目なの? …

SRM391 DIV2 Level.1

雪が積もってる区間が与えられて、どんだけの区間が雪で覆われてるのか求めろって問題。 与えられる区間のデータがかぶっていることもあるので、そこを考慮しないといけない。 using System; using System.Collections.Generic; using System.Text; public c…

SRM395 DIV2 Level.1

今日も元気に頭が悪いgray coderの私です。 せめてgreen目指したいよね!ということでこれからも頑張りたいところです。 0,1,4,9で構成される数字のn番目を求めろって問題。 こんなもんですかね? using System; using System.Collections.Generic; using Sy…

SRM434 Div2 Level.1

C#

5つの数値が与えられて、5つのうち最低でも3つの数値で割りきれる最小の数を求める問題。 総当たりで適当に解いた。 using System; using System.Collections.Generic; using System.Text; class LeastMajorityMultiple { public int leastMajorityMultiple(…

SRM413 DIV2 Level.1

C#

目的地までの距離、加速度、最高速度が与えられて、目的地にストップするまでにどれくらいの時間がかかるのか求めろという問題。 最高速度に達する場合とそうでない場合でわけないと駄目。 using System; using System.Collections.Generic; using System.Te…

SRM448 Div2 Level.2

C#

左・真ん中・右にカードのデッキがあって、とあるアルゴリズムに従ってカードをシャッフルする。 それが終わったあと真ん中のデッキの一番上のカードは何かという問題。総当たりのコードは簡単に書ける。が、大きい値を入れられると当然タイムオーバー。 usi…

SRM449 DIV2 Level1

C#

なんとなくC++からC#に移行しようと思ったので、C#の勉強を兼ねて簡単な問題を解いてみる。 ブラックジャックの点数を計算する問題。とても簡単。 今回charからintへの変換は一旦stringに変換してから行ったけど、普通はChar.GetNumericValue()を使ったほう…