ikemonn's blog

技術ネタをちょこちょこと

TopCoder

SRM 647 Div2 250 PeacefulLine

問題文 TopCoder Statistics - Problem Statement 書いた class PeacefulLine: def makeLine(self, x): counter = collections.Counter(x) count_arr = [] for word, cnt in counter.most_common(): count_arr.append(cnt) is_continue = True while is_cont…

SRM 636 Div2 250 GameOfStones

問題文 Limak has found a large field with some piles of stones. Limak likes perfection. It would make him happy if every pile had the same number of stones. He is now going to move some stones between the piles to make them all equal. Howe…

SRM 635 div2 250 IdentifyingWood

Problem Statement We call a pair of Strings (s, t) "wood" if t is contained in s as a subsequence. (See Notes for a formal definition.) Given Strings s and t, return the String "Yep, it's wood." (quotes for clarity) if the pair (s, t) is w…

【TopCoder】SRM164 DIV2 Lv.1

問題文概略 与えれた配列の中で一番文字数が多い要素と同じ文字数になるように、空白をつけよ。 書いたコード public class Justifier { public String[] justify(String[] textIn) { int max = 0; String x =""; for (int i = 0; i < textIn.length; i++){ …

【TopCoder】SRM453.5 DIV2 Lv.1

問題文概略 迷路を脱出させるのにできるだけ長い距離を移動させたい時の、脱出までにかかる移動距離を求める。 書いたコード import java.util.LinkedList; import java.util.Queue; public class MazeMaker { public int longestPath(String[] maze, int st…

【TopCoder】SRM425 DIV2 Lv.2

問題文概略 ロボットがランダムに東西南北に動く。n回ランダムに動くとき、一度通った道を通らずに動き続ける確率を求める。 書いたコード import java.util.Arrays; public class CrazyBot { //自分のいる場所 boolean[][] grid = new boolean[100][100]; /…

【TopCoder】SRM 162 DIV2 Lv.1

問題文概略 与えられた2つの数字の間の数全ての最小公倍数を求める。 書いたコード public class LCMRange { public int lcm(int first, int last) { int max = 1; boolean flag = false; int ans = 0; //maxを出す for(int i = first; i <= last; i++) { ma…

【TopCoder】SRM 161 DIV2 Lv.1

SRM 161 DIV2 Lv.1 問題文概略 カードを決められた人数に配るとき、それぞれの人の手持ちカードを求める 書いたコード import java.util.Arrays; public class CardCount { public String[] dealHands(int numPlayers, String deck) { String[] ans = new St…

【TopCoder】SRM 154 DIV2 Lv.1

問題文概略 商品の仕入れ値と売値から売上を算出する問題 書いたコード public class ProfitCalculator { public int percent(String[] items) { double cost = 0; double price = 0; double margin = 0; for(int i = 0; i < items.length; i++) { price += …

【TopCoder】SRM 155 DIV2 Lv.1

SRM 155 DIV2 Lv.1 問題文概略 特定の文字列を数字に変換する 書いたコード 解けなかった。 一時文字ずつ文字を調べていき、'X'が連続して出た数と’-’が出た数を数え、それぞれ数字に変換しようとしたが泥沼にはまった。 他の参加者のコードを読んで修正した…

【TopCoder】SRM 156 DIV2 Lv.1

SRM 156 DIV2 Lv.1 問題文概略 使っているディスク容量を、最適な形で分配する。 書いたコード(解けなかった) 全Totalの和 - 全Usedの和 = Marginを出す Usedの要素をsortする Margin - Usedの各要素 要素数 - 上記で0になるまで引けた個数 というように考え…

【TopCoder】SRM 157 DIV2 Lv.1

SRM 157 DIV2 Lv.1 問題文概略 数字の推測ゲーム。 範囲を絞っていき任意の数字を当てる。 書いたコード(解けなかった) 問題文をしっかり読んでおらず、upper boundが上書きされていくのを見逃してタイムアウト。 他の参加者のコードを読んで修正した public…

【TopCoder】SRM 158 DIV2 Lv.1

SRM 158 DIV2 Lv.1 問題文概略 文字列を規則にそって並べ替える。 書いたコード 全パターンが4つだったので、すべて書いた。 汎用性がない。。 public class TireRotation { public int getCycle(String initial, String current) { String char1 = initial.…

【TopCoder】SRM 159 DIV2 Lv.1

SRM 159 DIV2 Lv.1 問題文概略 道路図が文字列で与えられており、車を止めることのできる場所を求める。 書いたコード public class StreetParking { public int freeParks(String street) { String regex = "--B|-B|-D|-S-"; String replaceStreet = street…