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

AOJ 0107 - Carry a Cheese

aoj

対角線と直径で比較するだけの問題. 2番目の数値=全体ー1番小さいー1番大きいで求めており,乱雑です. #include <iostream> #include <algorithm> #include <cmath> using namespace std; int main(){ double a, b, c, d; while(cin >> a >> b >> c, a){ d = sqrt(pow(min(a, min(b</cmath></algorithm></iostream>…

AOJ 0183 - Black-and-White

aoj

これは長いなと思っていたら,意外と短いほうだった. しかし,納得の行かないコード #include <iostream> using namespace std; int main(){ string m[3]; while(std::cin >> m[0], m[0][0] != '0'){ for(int i=1;i<3;i++)std::cin >> m[i]; string w = "NA"; for(int</iostream>…

AOJ 0175 - A King in Hawaii

aoj

型云々でコンパイルエラーが出た. 適当にlong longにしてあげるとできた. #include <iostream> #include <vector> #include <algorithm> using namespace std; long long Decimal4(long long d){ std::vector<long long> v; while(d){ v.push_back(d%4); d /= 4; } long long j = 1, res = 0; for(i</long></algorithm></vector></iostream>…

AOJ 0195 - What is the Most Popular Shop in Tokaichi?

aoj

実装方法を少し考えた. #include <iostream> int main(){ int n, m, max; char s; while(std::cin >> n >> m, n&&m){ max = n + m, s = 'A'; for(int i=0;i<4;i++){ std::cin >> n >> m; if(n + m > max)max = n + m, s = 'B' + i; } std::cout << s << " " << max <<</iostream>…

AOJ 0207 - Block

aoj

書道をしないといけないのに何やってるんだろう. #include <iostream> #include <queue> #include <cstring> const int MAX_W = 100, MAX_H = 100; typedef std::pair<int,int> P; int map[MAX_H + 1][MAX_W + 1], w, h; int bfs(P sp, P gp, int c){ //来たことがあるかを格納 int f[MAX_H + 1</int,int></cstring></queue></iostream>…

AOJ 0173 - Haunted House

aoj

簡単な問題を潰す.明日の分は取っておくために明日から本気出す. #include <iostream> int main(){ std::string name, ns[9]; int am, pm, i=0, p[9] = {0}, pf[9] = {0}; //input for(;i<9;i++){ std::cin >> name >> am >> pm; ns[i] = name; p[i] = am + pm; pf[i</iostream>…

AOJ 0184 - Tsuruga Castle

aoj

適当な関数作って解いた. そんなこと必要ないけど,見やすさを重視しました. #include <iostream> #include <cstring> //年齢からインデックスを求める. int solve(int old){ if(old < 10){ return 0; } else if(old < 20){ return 1; } else if(old < 30){ return 2; } else</cstring></iostream>…

AOJ 0160 - Delivery Fee

aoj

そのまま実装すればいい. #include <iostream> int whatPrice(int, int); int main(){ int n; while(std::cin >> n, n){ int price = 0; while(n--){ int x, y, h, w; std::cin >> x >> y >> h >> w; price += whatPrice(x+y+h, w); } std::cout << price << std::end</iostream>…

AOJ 0159 - The Best Body

aoj

BMIから標準BMI22を引いた絶対値が標準との差,それを使うだけの問題. #include <iostream> #include <cstdio> #include <math.h> const int INF = 1000000, SBMI = 22; int main(){ int n; while(std::cin >> n, n){ double bbmi = INF; int bn = 0; while(n--){ //Input int i; doub</math.h></cstdio></iostream>…

AOJ 0133 - Rotation of a Pattern

aoj

回転ってどうやるの?と思って調べてコードを書きました. しかし,それは逆回転だった. #include <iostream> #include <cstring> int main(){ char map[8][8],t_m[8][8]; for(int i=0;i<8;i++){ std::cin >> map[i]; } for(int i=1;i<4;i++){ //角度分(90,180,270)</cstring></iostream>…

AOJ 0148 - Candy and Class Flag

aoj

入力された数を39で割ったときの余りを使えばできる. ただ,余りが0になったとき39番がクラス旗を手に出来ます. #include <cstdio> int main(){ int n; while(~scanf("%d",&n)){ int res = n%39?n%39:39; printf(res<10?"3C0%d\n":"3C%d\n",res); } }</cstdio>

AOJ 0139 - Snakes

aoj

普通に解いた. #include <iostream> //任意文字を消し全て消えてるか調べる関数 int clear(std::string s, std::string f){ int pos; while(pos = s.find(f), pos != std::string::npos) s.replace(pos,f.size(),""); if(s == "")return 1; return 0; } int main(){ i</iostream>…

AOJ 0138 - Track and Field Competition

aoj

単なる実装.少数の時はprintfを使うと書きやすい事に気づきました. 今回の場合は,精度が必要無いのでfloatでもよさそうですね. #include <iostream> #include <algorithm> #include <cstdio> struct athlete{int num; double time;}; bool tsort(const athlete& l, const athlete& r){</cstdio></algorithm></iostream>…

AOJ 0135 - Clock Short hand and Long Hand

aoj

正答率28.2%だが,簡単でしょww.すいません嘘でした. まず,長針と短針の角度計算を間違えていた. 長針は時間の影響も受けることを忘れていました. 次の問題は,長針は30 * H(hour) + 0.5 * M(min)ではないことです. これは,各々で計算しているため…

AOJ 0118 - Property Distribution

aoj

なんでTLEなのと思って他の方のコードを見ていたところWとHの入力順序を逆に捉えていました. それ以外は単純にDFS.蟻本の水たまり問題みたいに解ける. #include <iostream> const int MAX_H = 100, MAX_W = 100, v[4][2] = {{-1,0},{0,-1},{1,0},{0,1}}; std::strin</iostream>…

AOJ 0117 - A reward for a Carpenter

aoj

ワーシャルフロイド法を初めて解いた. #include <iostream> #include <cstdio> #include <algorithm> const int MAX_N = 20, INF = 500000; int dis[MAX_N+1][MAX_N+1]; //V 頂点数 from 始点 to 終点 int wfloyd(int V, int from, int to){ for(int k=0;k<=V;k++){ for(int i=0;i<=V;i++</algorithm></cstdio></iostream>…

AOJ 0110 - Alphametic

aoj

楽?いや楽ではない問題. 40桁を超える数が入ってくる場合があるからです. そのため多倍長に対応したものを書きましたが Wrong Answerだったので条件をよく見ると 2桁以上の「数字列」の左端の数字は 0 ではないものとします。 つまり,1桁の時は捨てちゃ…

AOJ 0505 - Questionnaire

aoj

sortの仕方を間違えて,初期化する位置も間違えてました. 注意したい. #include <iostream> #include <algorithm> struct place{int num;int votes;}; bool psort(const place& l, const place& r){ if(l.votes == r.votes)return l.num < r.num; return l.votes > r.votes; } i</algorithm></iostream>…

AOJ 0506 - String

aoj

今年は去年より多く解きたい. ループ構造が入り交じっているコード. #include <iostream> #include <sstream> std::string itos(int); int main(){ int n; while(std::cin >> n, n){ std::string s, res; std::cin >> s; while(n--){ res = ""; for(int i=0;i</sstream></iostream>