2012-02-01から1ヶ月間の記事一覧

POJ_1102 LC-Display

POJ

問題 数字と表示サイズがあたえられるので、電卓とかのディスプレイ風にして出力せよ。 例) INPUT: 2 12345 3 67890 0 0 OUTPUT: -- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | …

POJ_1543 Perfect Cubes

POJ

問題 N このとき、1 #include <cstdio> using namespace std; int n; int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i){ int i3 = i * i * i; int a3, b3, c3; for(int a = 2; a < i; ++a){ a3 = a*a*a; for(int b = a + 1; b < i; ++b){ b3 = b*b*b; if(i</cstdio>…

AOJ_0518 The Oldest Site

AOJ

問題 解法 2点を選んで1つの辺を作る. その辺が正方形をつくっているか調べるといい. #include <cstdio> #include <algorithm> using namespace std; const int MAX_HW = 5001; bool iseki[MAX_HW][MAX_HW]; int x[3000], y[3000]; int main(){ int n; while(scanf("%d", &n) &&</algorithm></cstdio>…

AOJ_0158 Collatz's Problem

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0158 ひさしぶりのHaskell たぶんlet式の意味を正確には把握していない main = do n <- getContents let vs = map (\cs -> (read cs :: Int)) $ words n putStr $ unlines $ map (\n -> show n) $…

AOJ_1030 Cubes Without Holes

AOJ

問題 解法 小さい立方体の状態は次の4とおり (a)とり除かれていない (b)1つ以上の方向からの穴によってとり除かれる (c)2つ以上の方向からの穴によってとり除かれる (d)3つの方向からの穴によってとり除かれる 求める答えaは a = n^3-(bの個数)+(cの個数)-(d…

AOJ_0528 Common Sub-String

問題 解法 動的計画法が使える。 詳しくはソースで #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAX_STRLEN = 4001; int len1, len2; char str1[MAX_STRLEN]; char str2[MAX_STRLEN]; int dp[MAX_STRLEN][MAX_STRLEN]; int solve(){ int </algorithm></cstring></cstdio>…

AOJ_1155 How can I satisfy thee? Let me count the ways...

問題 解法 P,Q,Rの値の組み合わせの総数は3^3=27通りなのでそれぞれに対して、 真になるか判定する。 構文解析は初めてだったのでちょっとてこずった。 #include <cstdio> #include <algorithm> using namespace std; int P, Q, R; char f[81]; int p; int formula(){ int val1,</algorithm></cstdio>…

AOJ_0130 Train

問題 解法 車両の移動を追っていって、今までにない車両の位置にきたら追加していけばいい。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; char str[1025]; char train[30]; int n; int main(){ char c; scanf("%d", &n); for(int i = 0; i < n; i++</cstring></algorithm></cstdio>…

AOJ_0118 Property Distribution

問題 解法 あるマスがまだ区画整理されていなければ、 1,区画の総数に1をたす。 2,区画整理したしるしをつける。 3,隣接するマスが(区画整理されていない&&同じ木の種類)ならば区画整理したしるしをつける。 4, 3を再帰的に行う。 区画整理されていないマス…

AOJ_0117 A reward for a Carpenter

問題 解法 有向グラフの最短経路を求める問題。 ワーシャルフロイド法をつかえば十分はやく求まる。 #include <cstdio> #include <algorithm> using namespace std; const int INF = 1 << 29; const int MAX_N = 21; int G[MAX_N][MAX_N]; int N, s, g; int HOUBI, HASHIRA; int</algorithm></cstdio>…

まだしばらく競技プログラミングはお休みしている

AOJ_0222 Prime Quadruplet

問題 四つ子素数を見つける問題。 制限時間が1秒と短かったので、こんなのでテーブル作って貼り付けることにした。 別にこんなことしなくてもいいかもしれない。 #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 10000001; bool prime[MAX_N]; </algorithm></cstdio>…

AOJ_0219

AOJ

問題 数えるだけ。 #include <cstdio> #include <algorithm> using namespace std; int kind[10]; int main(){ int n; while(scanf("%d", &n) && n){ fill(kind, kind + 10, 0); for(int i = 0; i < n; i++){ int k; scanf("%d", &k); kind[k]++; } for(int i = 0; i < 10; i++)</algorithm></cstdio>…

いそがしい

ちょっとテストがいっぱいあって、しばらく更新できそうにない。それに受験生ということを忘れていた。

AOJ_0112 A Milk Shop

解法 かかる時間が小さいほうから並べて足していくだけでいい。 カンニングしたら、signed int型だとオーバーフローするケースが あるらしいと分かったので、long longを使う。 コード #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 50000; i</algorithm></cstdio>…

AOJ_0106 Discounts of Buckwheat

久しぶりのDP。DPの考え方を一瞬わすれた。日頃からやっとかないとだめですね。 問題 これ #include <cstdio> using namespace std; int t[]={ 0,0,380,550,760,850,1100,1230,1400,1610,1520,1950,1870, 2070,2250,2244,2620,2624,2794,3004,3040,3344,3390,3590, 3</cstdio>…