C++

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

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

SRM477 DIV2 ImportantTasks

C++

並べ替えて比較するだけ。 #include <iostream> #include <vector> #include <string> #include <functional> #include <algorithm> using namespace std; class ImportantTasks{ public: int maximalCost(vector<int> complexity, vector<int> computers) { int sum = 0; int size = computers.size(); sort(complexity.</int></int></algorithm></functional></string></vector></iostream>…

SRM427 DIV2 LoveCalculator

C++

LOVEの各文字が何個がstringに入ってるかで相性がわかるんだってさー。 ____ /⌒ ⌒\ ホジホジ /( ●) (●)\ /::::::⌒(__人__)⌒::::: \ <で? | mj |ー'´ | \ 〈__ノ / ノ ノ#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; clas</algorithm></string></vector></iostream>…

SRM433 DIV2 250

C++

#include <iostream> #include <vector> #include <functional> #include <algorithm> using namespace std; class RoyalTreasurer{ public: int minimalArrangement(vector<int> A, vector<int> B) { sort(A.begin(), A.end()); sort(B.begin(), B.end(), greater<int>()); int size = A.size(); int sum = 0; for (i</int></int></int></algorithm></functional></vector></iostream>…

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

SRM 392 DIV2 250

C++

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

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

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

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

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

練習中

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

とりあえず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>…

Boostは便利

最近になってBoostを知ったので、いろいろと勉強してます。 特にformatが便利ですね。・ソース #include <iostream> #include <boost/format.hpp> using namespace std; using namespace boost; int main(void) { cout << format("%1%") % "boostって便利だなー" << endl; cout << format</boost/format.hpp></iostream>…

cvBlobを使ってみる

http://code.google.com/p/cvblob/ 二値画像のラベリングや重心などの特徴抽出が行えるOpenCV用のライブラリcvBlobを使ってみる。 ダウンロードして、ファイル(cvblob.h, cvblob.cpp and cvlabel.cpp)を自分のプロジェクトに加えるだけで使える。とりあえず…

Hello, World

C++

C++勉強しなくちゃなーと思い立ち、とりあえず参考書として"C++実践プログラミング"を入手。勉強するぞー。 というわけでまずはHello,World。 #include <iostream> int main(void) { std::cout << "Hello, World\n"; return (0); }</iostream>