2012-03-01から1日間の記事一覧

AOJ - Problem 0114 : Electro-Fly

AOJ

問題文 x,y,zがそれぞれ何回で1に戻ってくるか計算し、その回数をa,b,cとするとa,b,cの最小公倍数が答えになるようです。long int(32bit)ではオーバーフローするので注意が必要です。 #include <iostream> using namespace std; typedef long long int ll; ll gcd(ll a</iostream>…

AOJ - Problem 0110 : Alphametic

AOJ

問題文 覆面算の問題です。Xの部分に0-9のどれかの数字が入るので10通り調べるとよいです。数値に変換するとオーバフローするので文字列のまま足し算しましょう。多倍長整数が標準で存在する言語だと楽ができることでしょう。 #include <iostream> #include <string> #include <algorithm></algorithm></string></iostream>…

AOJ - Problem 0106 : Discounts of Buckwheat

AOJ

問題文 入力された整数nに対しnグラムのそば粉を買うときの最小の金額を求める問題です。入力される範囲が[500,5000]と小さく、すべて100の倍数なので初めに計算しておくとよいです。 #include <iostream> #include <algorithm> using namespace std; const int INT_MAX = 1e+7; i</algorithm></iostream>…