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

自動アンパッカーについて

マルウェア/ウイルスの静的解析を困難にするために、難読化させることをパッキングといいます。そんでもってそれを解除することをアンパッキングといいます。 いろんな統計がありますが、出回っているマルウェアの70〜80%以上がパックされているらしいです。…

人材獲得作戦・4

TLで見かけた問題を解いてみた。 http://okajima.air-nifty.com/b/2010/01/post-abc6.html ん・・・これだとLv.3になるのかな?いや大丈夫だよね。 file_name = "maze.txt" f = open(file_name, 'r') maze = [] start = None goal = None x = 0 y = 0 for li…

辞書をGoogle App EngineのDatastoreに突っ込む

Datasotreに辞書を入れたいなーと思う。 問題は辞書型用のプロパティクラスが用意されてないこと。 これを解決するために pickleで辞書をバイナリ化 BlobPropertyのモデルを作る Blobにバイナリを入れる を行えばおk。 こんな感じですな。 class DictModel(…

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

pydbgでAnti-Anti-Debugging

マルウェアなどがデバッグを難しくするためのテクニックの1つにAnti-Debuggingといわれるものがあります。 その名の通りデバッグを中止させるためのテクニックです。 Windows Anti-Debug Reference リンク先で紹介されているIsDebuggerPresent()を用いたAnti…

ネット上の画像をIplImageに変換

前教えてもらったやり方を記事にまとめておく。 C++/CLIで.NET Frameworkを使って画像をいったんBitmapに変換し、それから中身をIplImageに格納する。 IplImage* GetIplImage() { IplImage *img = 0; String^ url = URL; HttpWebRequest^ request; HttpWebRe…

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…

Python 2.5でPyDbgを動かす

リバースエンジニアリングフレームワークPaiMei(http://pedram.redhive.com/PyDbg/docs/)の中に含まれているピュアPythonなWindowsデバッガーPyDbgがPython 2.5で動かない! Traceback (most recent call last): File "C:\Python25\test.py", line 2, in <module> fr</module>…

SRM395 DIV2 Level.1

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

pefileとpydasm

pythonのライブラリ pefileとpydasmの日本語情報があんまり見つからなかったんで紹介記事書いてみるテスト。 まず、何ができるの? pefileはWindowsの実行形式Portable Executableの解析を手助けしてくれるライブラリ。 pydasmはx86の逆アセンブルができるラ…

Last.fm APIを使ってアルバムアートを入手

外部ツールでリッピングすると、WMPのライブラリに入れてもWMPがアルバムアートを取得してくれないんでムカムカしてアルバムアートを取得するスクリプトを書いた。 Last.fmのAPIからアルバムアートのURLを取得し、そのURLから画像を.jpgで保存する。 ライブ…

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()を使ったほう…

OpenCV 2.0

OpenCV 2.0がリリースされましたね。 早速インストールしてVisual Studioで使えるようにしてみました。 http://www.atinfinity.info/wiki/index.php?OpenCV/SVN%E7%89%88%20OpenCV%E3%83%93%E3%83%AB%E3%83%89 上の記事を参考にCMakeして、後は普通にVisual …

Wicket勉強中

WicketをNetBeans + Tomcatで勉強中。 ネット上の例を見てると「import org.apache.wicket.examples.WicketExamplePage;」がよく出現するけどこんなんどこにあるんだよと思って調べて見た。 答え:通常配布されているWicketのライブラリ中に存在。 NetBeans…

Windows上で実行中のプロセスを表示

Deviare(http://www.nektra.com/products/deviare-api-hook-windows/) Python Win32 Extensions(http://python.net/crew/mhammond/win32/Downloads.html) 実行するにはこの二つがインストされてること。 Deviareの練習がてらに書いてみました。 import win32…