2009-01-01から1年間の記事一覧

SRM446 DIV2

C++

#include <iostream> #include <cmath> using namespace std; class SoldierLabeling{ public: int len(int number) { int sum = 1; while (number >= 10){ sum ++; number /= 10; } return sum; } int count(int n, int lowerBound, int upperBound) { int sum = 0; int i = </cmath></iostream>…

MSHTMLでHTMLパース

なにこれ面白い。 WindowsならMSHTML COMコンポーネントを使ってHTMLをパースできちゃう。 import win32com.client import urllib2 data = urllib2.urlopen("http://www.python.org").read() html = win32com.client.Dispatch("htmlfile") html.write(data) …

SRM 392 DIV2 250

C++

キャンディのlifetimeを求めろとかなんとか。 lifetimeの意味を取り違えてしまったので、問題文を読み解くのに少し時間がかかった。 プログラム自体は楽勝。 #include <vector> #include <iostream> using namespace std; class AverageCandyLifetime { public: double getAver</iostream></vector>…

PythonでWin APIをフック

WindownのAPIをフックしたい、と思ったけどC/C++だと覚えないといけないことが多くて面倒。 なのでAPI Hook(DLLインジェクション)ができるライブラリDeviare(http://www.nektra.com/products/deviare-api-hook-windows/)を使ってPythonでAPIをフックしてみる…

PyQt4の練習

Qt

http://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/ ここを参考にQt Creator + PyQtに挑戦してみる。上のチュートリアルを日本語にしただけでごわす。 まずはQt Creatorを起動して、新規作成からQtデザイナーフォームを選択。 フォームテンプレートでWidg…

SRM 437 DIV2 250

C++

簡単すぎて笑ってしまった。 あ、でもこれはm.size()を返すだけでよかったか。 #include <string> #include <iostream> #include <map> #include <sstream> using namespace std; class TheBeauty{ public: int find(int n){ map<char, bool> m; stringstream tmp; string number; map<char, bool>::iterator it; tmp <</char,></char,></sstream></map></iostream></string>…

Last.fmのAPIを利用してアルバムアートのURLを取得

すげー適当に書いた。 後悔はしていない。 #!-*- coding: utf8 -*- import urllib2 import re api_key = APIのキー artist = アーティストの名前 album = アルバムの名前 #アーティストとアルバムは1対1で対応していること for i in range(len(artist)): art…

cron

GAE

放置してたらcronが動いてた。 寝る。

Google App EngineでCronが動かない

GAE

Google App Engineを初めて見た。初めて見たのは良いけれど、cronで躓く。 Hasn't run yetってなんでだろうか。・cron.yaml cron: - description: jobs url: /cron/job schedule: every 5 minutes どこがアレなのかな・・・。

いもげスレtoXML

PHPとPythonの勉強を兼ねて、id:vert771さんのコード(http://imgscraper.sourceforge.jp/)をPython(3.1)に置き換えて見た。 正規表現とか文字コードとか色々適当です。うげえ。 きっともっと効率のよいやり方があるはず。あと'>'の処理も適当。本文抽出も適…

Cuda

Cuda + OpenCV + C++/CLIで開発・・・は辞めたほうがいいのかな? せめてネイティブにしたほうがいろいろ楽な予感

HTMLタグを取り除く

http://www.codereading.com/codereading/python/strip-html-tags.html ここを参考にしてHTMLタグを取り除こうと思ったら、Python 3.x系からはsgmllibが無くなってるみたいなので少し書き換え。といってもライブラリのところを置換しただけですが。 import h…

SRM 409 DIV2 250

C++

64cmの棒があって、望みの長さの棒を作るためにその棒を半分に折っていく。望みの棒は何個の棒から成り立っているのか求めろという問題。 うまく説明できてないかな? 最初は解き方がよくわからなかったけど、これは2進数に変換して何個1が立っているかを求…

SRM 435 DIV2 250

C++

あーなんかアレだ。'0'を引いてやれば整数にできるんだった。完璧に忘れてた。 まあそこが引っ掛かったぐらいの問題です。 #include <iostream> #include <string> using namespace std; class SkiFriction { public: int bestPosition(string skiFriction, string pathFrictio</string></iostream>…

うーん

並列化難しいです。 これ読もうかな、と思ったらテンプレートの知識が必要なよう。 真面目にC++勉強するかな。ベターCぐらいにしか今まで考えてなかったわ。

私的Parallel Studioまとめ

今度Parallel Studioが手に入る予定。 手元に届く前前にParallel Studioに関する情報をまとめてみる。 Prallel Studioとは何か Parallel StudioはVisual StudioでのC/C++向けに設計された、並列化を実装するためのツール。 並列化を簡単に実装できる。 既存…

SRM422 DIV2 250

C++で書いてたらどういうデータ型を使えばいいのかわからず小一時間ぐらい悩む。 そのままint型で処理してもいいけど、それだとちょっと面倒臭い。string型は正直なところよく他へのキャストの仕方がわかってない。 なのでPythonでちゃちゃっと書いてみる。…

SRM421 DIV2 250

C++

トレーニングして心拍があがって、その心拍数が最大値と最小の間にあるよう気をつけながらトレーニングするとかなんかそんな問題。簡単すぎる。 #include <iostream> using namespace std; class GymTraining{ public: int trainingTime(int needToTrain, int minPulse</iostream>…

SRM443 DIV2 250

C++

サッカーリーグの勝ち点を求める問題。 std::stringとcharのキャストにとまどる。 俺アホだな。 #include <string> #include <vector> using namespace std; class SoccerLeagues{ private: int getHome(char s){ string str =""; str += s; if (str == "W"){ return 3; }els</vector></string>…

SRM 428 DVI2 500

C++

与えられた文字列の隣同士が異なる場合が何個あるか数えろという問題。 順列組み合わせを自分で書こうとして手間だったけど、早々にあきらめてSTLのAlgorithmを使用すると一瞬で解決。 next_permutationが便利すぎるんじゃ。 #include <string> #include <algorithm> using name</algorithm></string>…

System::Net::HttpWebRequestの例外処理

http://msdn.microsoft.com/ja-jp/library/system.net.httpwebresponse.statuscode(VS.80).aspx

SRM 419 DV2 500

C++

簡単なテキストエディタを想定して、それにundoを実装する問題。 #include <vector> #include <string> using namespace std; class Undo{ private: bool isType(string command){ string::size_type index = command.find("type"); if (index == string::npos){ return fals</string></vector>…

SRM 419 DIV2 250

C++

与えられた配列から周囲長を算出する問題。 簡単。 #include <vector> #include <cmath> using namespace std; class ColumnDiagramPerimeter{ public: int getPerimiter(vector <int> a){ int ans = 0; int size = a.size(); ans += size * 2; ans += a[0]; for (int i = 1; i <</int></cmath></vector>…

練習してます

C++

SRM 335 DIV2 250 回文を作れという問題。 1つだけテストを通らなかったので作り直した。しょうもない間違いでした。 #include <vector> #include <string> #include <iostream> using namespace std; class Palindromize{ public: string minAdds(string s) { string tmp, ans; int si</iostream></string></vector>…

数学英語

http://homepage2.nifty.com/PAF00305/math/writing.html

iddy

iddyに登録してみた。 使い方がまだよくわかんね。

練習中

C++

C++の練習がてらに簡単なTopCoderの問題を解いてみる。 SRM 255 DIV2 250 #include <iostream> #include <algorithm> #include <vector> #include <string> #include <sstream> using namespace std; class SequenceOfNumbers{ public: vector <string> rearrange(vector <string> sequence){ vector <int> numbers; vector <string> ans;</string></int></string></string></sstream></string></vector></algorithm></iostream>…

メモり

BoostをVisual C++で使いたいときはBoostPro(http://www.boostpro.com/)が便利。 bjamより速くて簡単でごわす。

とりあえずlibSVMを使ってみる

C++

libSVMをとりあえず使ってみる。SVMのタイプはONE CLASS。 こんな感じのデータを突っ込んでみた。イメージはイメージ。 #include "svm.h" #include <iostream> #include <list> using namespace std; struct point { double x, y; signed char value; }; const int current_v</list></iostream>…

ヘッダを読み飛ばし

id:Schimaさんの指摘とおりにbitmapのヘッダを読み飛ばしてみる。 そうすると想定通りの結果が得られた。といってもimgeDataに値を突っ込む前に54回ReadByte()させるだけだが。 こんな簡単なことに気づかないなんて呆けてました・・・。 id:Schimaさんありが…