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

AOJ 0513 - Shuffle The Cards

aoj

書いたコードでは例外的な入力があったので,条件処理しちゃうあたり残念. 一般化できたら載せます.

AOJ 1008 - What Color Is The Universe?

aoj

銀河鉄道の夜は読んだことがないです. 「僕達はどこへだって行ける気がしたんだ.」->オーバーフロー. 作品が違いますね. #include <iostream> #include <map> int main(){ int n; while(std::cin >> n, n){ std::map<long long int, int> stars; int max_num = 0, max_time = 0; for(int i=0</long></map></iostream>…

AOJ 1009 - Greatest Common Divisor

aoj

英語が読めるようになりたいです. #include <iostream> int main(){ int a, b; while(std::cin >> a >> b, !std::cin.eof()){ while(b){ int c = b; b = a % b, a = c; } std::cout << a << std::endl; } }</iostream>

AOJ 0565 - Lunch

aoj

いつかに解いた気がするのです. #include <iostream> #include <algorithm> int main(){ const int INF = 10000000; int min_p = INF, min_j = INF; for(int i=0;i<5;i++){ int n; std::cin >> n; if(i < 3) min_p = std::min(min_p, n); else min_j = std::min(min_j, n); } std</algorithm></iostream>…

AOJ 0522 - JOI and IOI

aoj

前作った関数が使えると思ったら無理でした. posを1つずつ動かすことで"IOIOI"のようなものに対応した. #include <iostream> int findText(std::string text, std::string oldText){ int times = 0, pos = 0; while(pos = text.find(oldText, pos), pos != std::stri</iostream>…

AOJ 0074 - Videotape

D言語で解いた. import std.stdio; void SectoTime(int sec){ int h = sec / 3600, m = sec % 3600 / 60, s = sec % 3600 % 60; writefln("%02d:%02d:%02d", h, m, s); } void main(){ int h, m, s; while(1){ readf("%d %d %d\n", &h, &m, &s); if(h == -1…

AOJ 0071 - Bombs Chain

aoj

深さ優先で行きましょう. #include <iostream> int map[14][14]; void dfs(int x, int y){ map[y][x] = 0; int vx[] = {-1, 0, 0, 1}, vy[] = {0, -1, 1, 0}; for(int i=0;i<4;i++){ for(int j=1;j<=3;j++){ if(map[y+vy[i]*j][x+vx[i]*j] == 1) dfs(x+vx[i]*j, y+vy[</iostream>…

AOJ 0072 - Carden Lantern

aoj

Prim法を使って解いた. 辺としてその道の灯篭の数を置いた. a->bがあれば,b->aもあるんだよ自分. #include <iostream> #include <algorithm> #include <cstdio> const int INF = 10000000; int main(){ int n, m; while(std::cin >> n, n){ std::cin >> m; int cost[100][100]; for(in</cstdio></algorithm></iostream>…

Project Euler 0014

コラッツ予想を利用した問題. 最初D言語で書こうとしたらOverFlowしてしまったので,いくらでも入るRubyに. 久しぶりというか滅多に書かないので,いろいろ抜けてた. benchmarkさんで速度を調べたところ適当に書いて23sのところ,dpっぽくすると1sになっ…

AOJ 0220 - Binary Digit A Doctor Loved

aoj

晒そうと思いましたが,すごく汚いのでやめました.

AOJ 0227 - Thanksgiving

aoj

貪欲法みたいな.高い順にグループをつくり,最も低い分を引いてあげましょう. #include <iostream> #include <algorithm> #include <vector> int main(){ int n, m; while(std::cin >> n >> m, n){ int total = 0; std::vector<int> pvec; for(int i=0;i<n;i++){ int p; std::cin >> p; pvec.push_back(p); total += p; </n;i++){></int></vector></algorithm></iostream>…

AOJ 0219 - A Popular Ice-cream Shop

aoj

オーナーはGUIが嫌いなんですね. #include <iostream> int main(){ int n; while(std::cin >> n, n){ int ice[10] = {0}; for(int i=n;i;i--){ int t; std::cin >> t; ice[t]++; } for(int i=0;i<10;i++){ if(ice[i]) for(int j=ice[i];j;j--) std::cout << "*"; else</iostream>…

AOJ 0226 - Hit and Blow

aoj

Hit&Blowの問題. コード内はBlowがBrowになってますが気にしない. ショートコーディングは辛かったのでやめました(技術の欠如) #include <iostream> int main(){ std::string a, b; while(std::cin >> a >> b, a != "0"){ int hit = 0, brow = 0, as[10] = {0}, bs</iostream>…

D言語でAOJを解く企画

AOJでD言語が実装されたので,2問だけ解いてみました. 暫時更新していく予定です. D言語初心者のため,あまり参考になりません.0000 import std.stdio; void main(){ writeln("Hello World"); } 0001 import std.stdio; void main(){ for(int i=0;i<10;i…

AOJ 0217 - Walking in the Hospital

aoj

計算するだけの問題は楽だなー #include <iostream> int main(){ int n; while(std::cin >> n, n){ int max_p, max_d = 0; for(;n;n--){ int p, d1, d2; std::cin >> p >> d1 >> d2; if(d1 + d2 > max_d) max_p = p, max_d = d1 + d2; } std::cout << max_p << " " << </iostream>…

AOJ 0216 - Cutting Down Water Bills

aoj

Cでも書けそうな気がしたんだ. #include <iostream> int main(){ int w; while(std::cin >> w, w+1){ int p = 1150; if(w > 30)p += 2650 + (w-30) * 160; else if(w > 20)p += 1250 + (w-20) * 140; else if(w > 10)p += (w-10) * 125; std::cout << 4280 - p << std</iostream>…

AOJ 0206 - Next Trip

aoj

ショートコーディング風に書いたら気持ち悪くなった. そして,さらに減らそうとしたら詰んだ. #include <cstdio> int main(){ int l; while(scanf("%d", &l), l){ int cm = -1; for(int i=1;i<=12;i++){ int m, n; scanf("%d%d", &m, &n); l -= m - n; if(l <= 0 &</cstdio>…

AOJ 0205 - Rock, Paper, Scissors

aoj

2人から5人へと進化したじゃんけん問題 break使ってる時点でgotodisれないとTwitterで見た気がした. 最初,全員が同じ手を出したらあいこという条件を忘れていました. #include <iostream> int main(){ //紙 3 はさみ 2 石 1 bool eflag = false; while(!eflag){ int</iostream>…