AOJ

AOJ0091

AOJ

問題:Blur解法:DFS 適当にやると計算量とメモリが爆発しそうなので、無駄に枝をはやさないように気をつける。 左上から右下に向かう落としかたに限定して、行単位で全部消えない場合はそこで探索をうちやめる。 盤面のコピーはとらず1つの盤面を使い回す(…

AOJ0200

AOJ

Traveling Alone: One-way Ticket of Youth ワーシャルフロイド法って実は使ったことなかった。 mの存在感がない。 timeって使ったらgccさんが怒るらしいのでtimuにした(恥ずかしい)。 #include<iostream> #include<algorithm> using namespace std; const int N = 110; int timu</algorithm></iostream>…

AOJ0131

AOJ

問題:Doctor's Strange Particles ライツアウトの解を求める。1個しか解がないと言う甘え仕様。 上から順番に処理していく。 まず1行目について全パターンの押し方を試す。 i行目はi-1行目を全て消さないと行けないので、押し方は一意に定まる。 そして一番…

AOJ0129

AOJ

問題:Hide-and-Seek Supporting System 円と2点の間の線分の当たり判定。ただし2点が両方共円の中にある場合は無視する。 #include<iostream> #include<vector> #include<complex> using namespace std; int main() { int n,m; while(cin >> n,n) { vector<complex<double> > wallp; vector<double> wallr; for</double></complex<double></complex></vector></iostream>…

AOJ0120

AOJ

問題:Patisserie DP難しい。 DPわけわからん。 #include<iostream> #include<string> #include<sstream> #include<vector> #include<cmath> using namespace std; int main() { string s; while(getline(cin,s), !s.empty()) { stringstream ss(s); int W; ss >> W; vector<int> R; int r; while(ss >> r) R.</int></cmath></vector></sstream></string></iostream>…

AOJ0176

AOJ

問題:What Color? 16進数で入力してやるだけ。 #include<iostream> #include<cstdio> #include<string> #include<map> #include<cmath> using namespace std; double d( int a, int b ) { double dr = (a&0xff0000) - (b&0xff0000); double dg = (a&0x00ff00) - (b&0x00ff00); double db = (a&0x000</cmath></map></string></cstdio></iostream>…

AOJ0122

AOJ

問題:Summer of Phyonkichi 時間差で動作するスプリンクラーの下をカエルのぴょん吉が渡る問題。 生死が掛かっているにも関わらず、ジャンプすることを強いられている。 #include<vector> #include<map> #include<iostream> #include<algorithm> using namespace std; #define debug(a) cout <<</algorithm></iostream></map></vector>…

AOJ0121

AOJ

問題:Seven Puzzle スライドパズルの最短スワップ回数を求める。 幅優先した。 #include<iostream> #include<vector> #include<map> #include<algorithm> #include<queue> #include<cstdio> using namespace std; #define rep(i,n) for( int i=0; i<n; ++i ) #define INF 1<<21 int main() { map< vector<int> , int > memo; vector<int> in(8); rep(i,8)…</int></n;></cstdio></queue></algorithm></map></vector></iostream>

AOJ0118

AOJ

問題:Property Distribution やるだけ問題。 再帰苦手なので再帰で書いた。 入力がw,hの順じゃなくてh,wの順でWAした。 #include<iostream> using namespace std; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; int dfs( char f[110][110] ,char c, int x , int y ) </iostream>…

AOJ0114

AOJ

問題:Electro-Fly mod取ってぐるぐる循環する奴が1周回るのにどれだけかかるかを求める問題。 愚直なループだとTLEするので、x,y,z別に求めてそれの最小公倍数で良い。 O(1)で求める解法ありそうだけどしらん。 #include<iostream> using namespace std; template<class t> t gc</class></iostream>…

AOJ0109

AOJ

問題:Smart Calculator 四則演算の計算機。 以前貼りつけた文字列を計算するやつが超絶バグっていてやばかった。 構文解析ってどうやってやるの?とかいいながら構文解析 Howto(もう答え)を参考にしながらポチポチした。ほぼ写経。 #include <iostream> #include <string> #in</string></iostream>…

AOJ0503

AOJ

問題:Cup kyuridenamida「がんばって幅優先です」 といわれてがんばった。 きたないけどゆるしてね #include<iostream> #include<vector> #include<queue> #include<map> using namespace std; struct Node { int a,b,c; Node():a(0),b(0),c(0){} bool operator < ( const Node& other ) co</map></queue></vector></iostream>…

AOJ0090

AOJ

問題:Overlaps of Seals 半径1のシールが重なっている枚数の最大を求める問題. 接触している場合(中心どうしの距離が2)の場合も重なっているとみなす. すなわち,最大枚数になっている領域は必ずいずれかの交点を含む. すべての交点を求め,そこから半径…

AOJ0041

AOJ

問題:Expression なんか数字が4つ与えられるので演算子や()をつかって値が10になる式を出力する問題. 超頭が悪い事をしてしまった.黒歴史だけど記念に掲載.あー頭わるい #include <iostream> #include <string> #include <sstream> #include <vector> #include <algorithm> #define DEBUG(a) //cerr << #a </algorithm></vector></sstream></string></iostream>…

AOJ0037

AOJ

問題:Path on a Grid グリッド上の壁情報を与えられ,初期位置から右手づたいに進んでいき,初期位置まで帰ってくるまでの移動方向を出力する問題. 壁情報を配列で扱いやすいよう整理し,それをたどればOK.自分はサンプル入力の1111 00001 0110 01011 0010 …

AOJ0070

AOJ

問題:Combination of Number Sequences 0以上の整数n,sが与えられ, k1 + 2 × k2 + 3 × k3 + ... + n × kn = s となるような組み合わせが何通りあるかを答える問題. ただし,kは0から9まででそれぞれ1回しか使えない.幅優先で探索+自明な枝刈り.10秒超でT…

AOJ0040

AOJ

問題:Affine Cipher アフィン暗号で暗号化された文字列を復号する問題. F(γ) = (α・γ+β) mod 26 文字列の各文字はこの式に基づいて暗号化されている.αとβは分からない. ただし,元の文字列には必ず"this"か"that"が入っているのでここからαとβを求め,文…

AOJ0043

AOJ

学校来たけど用事ある人全員来てなかったので図書館のPCでコーディング.問題:Puzzle パズルという名の麻雀,の待ち判定. 再帰のほうが無駄なくかける気がするけど,特に工夫しなくても間に合いそうなのでただの幅優先. 再帰書くの苦手なので今度再帰でも書…

AOJ0042

AOJ

ソースコードの貼付けテストとして.問題:A Thief 1年近く前に解いたナップザック問題. 初めて解いたDP.今ならもっときれいに書けると思う. #include <iostream> #include <map> #include <vector> #include <string.h> #include <cstdio> #include <set> #define rep(i,n) for(i=0;i</set></cstdio></string.h></vector></map></iostream>