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

ARC #001のA(センター採点)

Aなら解ける...はず.あと24分で新年ですね. #include<iostream> int main(){ int n; std::cin >> n; std::string str; std::cin >> str; int a[4] = {0}; for(int i=0;i</iostream>

AOJ 0059 - Intersection of Rectangles

aoj

色々やったんですがWAだったので,違う方法にしました. 重ならない方から調べます. #include<iostream> struct P{ double x, y; }; int main(){ P ps[4]; while(std::cin >> ps[0].x >> ps[0].y >> ps[1].x >> ps[1].y >> ps[2].x >> ps[2].y >> ps[3].x >> ps[3].y,</iostream>…

AOJ 0186 - Aizu Chicken

aoj

会津鶏肉の量で二分探索する. #include<iostream> #include<cstdio> const int INF = 1 << 24; int q_chicken, b, p_chicken, p_aizu, q_aizu; bool C(int x){//x: 買う会津鶏肉の量 if(x * p_aizu > b || x > q_aizu){//資金超えるか用意された量より多い return false; } re</cstdio></iostream>…

AOJ 0181 - Persistence

aoj

はじめての2分探索. #include<iostream> const int INF = 1 << 24; int m, n, a[100];//dansu, honsu bool C(double x){ int i = 0, j = 0, l = 0; while(i < n && j < m){ if(l + a[i] <= x){//入る l += a[i]; i++; }else{//もう入らない l = 0; j++; } } if(i == n</iostream>…

AOJ 0218 - Dividing Students

aoj

#include<iostream> int main(){ int n; while(std::cin >> n, n){ while(n--){ int pm, pe, pj; std::cin >> pm >> pe >> pj; int sum = pm + pe + pj; if(pm == 100 || pe == 100 || pj == 100){ std::cout << "A" << std::endl; }else if(pm + pe >= 180){ std::cou</iostream>…

AOJ 0166 - Area of Polygon

aoj

#include<iostream> #include<cmath> #include<cstdio> double abs(double d){ return (d>0)?d:-d; } int main(){ int m, n; while(std::cin >> m, m){ double Sm = 0, Sn = 0; int remained_angle = 360; for(int i=0;i<m-1;i++){ int angle; std::cin >> angle; Sm += sin(1.0 * angle * M_PI / 180); remained_angle</m-1;i++){></cstdio></cmath></iostream>…

(BITで)AOJ 0167 - Bubble Sort(回数を調べる)

aoj

小さい順に1,2,3,...,nとつけて,BITをつかえばいいとかとか. #include<iostream> #include<algorithm> #include<map> const int MAX_N = 100; int bit[MAX_N+1], n; int sum(int i){ int s = 0; while(i > 0){ s += bit[i]; i -= i & -i; } return s; } void add(int i, int x){ whil</map></algorithm></iostream>…

AOJ 0167 - Bubble Sort

aoj

ただのBubbleSortさん.見たときはBITで解くかとおもっていた. BITで解けるか試してみる. #include<iostream> int main(){ const int MAX_N = 100; int n, a[MAX_N]; while(std::cin >> n, n){ for(int i=0;i<n;i++){ std::cin >> a[i]; } int t = 0; while(true){ bool update = false;</n;i++){></iostream>…

AOJ 0163 - Highway Toll

aoj

&& > ||(同順位でない) #include<iostream> int toMinute(int h, int m){ return h * 60 + m; } int roundUp(int i){ if(i % 50){ return i - (i % 50) + 50; } return i; } //17*60+30 = 1050 //19*60+30 = 1170 int main(){ int MAX_N = 7; int d[MAX_N+1][MAX_N+1],</iostream>…

AOJ 0141 - Spiral Pattern

aoj

n=2だけ特別視 #include<iostream> #include<algorithm> #include<cstdio> int main(){ const int MAX_N = 100; const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; int d, n; std::cin >> d; for(int k=0;k<d;k++){ std::cin >> n; if(k > 0){ std::cout << std::endl; } if(n == 2){ std::cout << "##\</d;k++){></cstdio></algorithm></iostream>…

AOJ 0120 - Patisserie

aoj

すこしbitDP書けるようになった.いままでループで,はじめてメモ化再帰書いた. こっちのほうがいいかも.Sは今まで使ったケーキ,vはさっき使ったケーキ dp[S][v]は残りのケーキでできる最小幅. 全ケーキの幅になるよう最初に使ったケーキの半径と最後に…

AOJ 0162 - Hamming Numbers

aoj

#include<iostream> int main(){ int arr[1000001] = {0, 1, 1, 1, 1, 1}; for(int i=6;i<=1000000;i++){ if((i%2 == 0 && arr[i/2]) || (i%3 == 0 && arr[i/3]) || (i%5 == 0 && arr[i/5])){ arr[i] = 1; }else{ arr[i] = 0; } } int m, n; while(std::cin >> m >> n,</iostream>…

AOJ 0142 - Nature of Prime Numbers

aoj

何かTLEするとおもっていたら,n=1がだめだったようです. n=1のとき,vのサイズが0です. (1)の部分を最初for(int i=0;i #include<iostream> #include<vector> #include<algorithm> int main(){ int n, arr[5000]; std::vector<int> v; while(std::cin >> n, n){ std::fill(arr, arr+5000, 0);</int></algorithm></vector></iostream>…

AOJ 0111 - Doctor's Memorable Codes

aoj

#include<iostream> #include<map> std::string to_bs(int i){ std::string s = ""; while(i > 0){ s = static_cast<char>(i%2+'0') + s; i /= 2; } while(s.length() < 5){ s = '0' + s; } return s; } int main(){ std::map<char, std::string> input; std::map<std::string, char> output; output["101"] = ' '; outpu</std::string,></char,></char></map></iostream>…

AOJ 0121 - Seven Puzzle

aoj

ほんとうにきたないのでかきたくない.

AOJ 0180 - Stellar Performance of the Debunkey Family(Kruskal法)

aoj

コードがながい.unique_ptrがつかってみたかったのだけど,使い所間違っているかなー. kruskal法はむずかしいと思っていましたが,そうでもなかったです. #include<iostream> #include<memory> #include<vector> #include<algorithm> class UnionFind{ private: int n; std::unique_ptr<int[]> par, ra</int[]></algorithm></vector></memory></iostream>…

AOJ 0180 - Stellar Performance of the Debunkey Family(Prim法)

aoj

タイトルがながい #include<iostream> #include<algorithm> const int MAX_N = 100, MAX_M = 100, INF = 1 << 24; int n, m; int cost[MAX_N][MAX_N], mincost[MAX_N], used[MAX_N]; int prim(){ std::fill(mincost, mincost+MAX_N, INF); std::fill(used, used+MAX_N, 0); mincos</algorithm></iostream>…

AOJ 0189 - Convenient Location

aoj

久しぶりにdijkstra法. 忘れていたので蟻本を読みながら書いた. #include<iostream> #include<algorithm> const int MAX_V = 10, INF = 1 << 24; int V; int d[MAX_V], used[MAX_V], cost[MAX_V][MAX_V]; void dijkstra(int s){ std::fill(d, d+MAX_V, INF); std::fill(used, us</algorithm></iostream>…

AOJ 0169 - Blackjack

while s = gets.chomp break if s == "0" res = 0 one_n = 0 s.split(" ").map{|e| e.to_i }.each{|e| if e == 1 then one_n += 1 elsif e >= 10 && e <= 13 res += 10 else res += e end } f = false for i in 0..one_n #i: 1をそのまま使う数 if res + i +…

AOJ 0177 - Distance Between Two Cities

aoj

sin,cos,tanは弧度法で指定しないといけないことで数分悩んだ. #include<iostream> #include<cmath> double toDegree(double a){ return M_PI / 180 * a; } int main(){ const double R = 6378.1; double a, b, c, d; while(std::cin >> a >> b >> c >> d, a != -1){ //弧度</cmath></iostream>…

AOJ 0143 - Altair and Vega

aoj

AOJ 0035 - Is it convex? - ノートの切れ端でつかった外積を用いた. ライブラリつくって使いまわしたい. #include <iostream> #include <cstdio> struct P{ double x, y; }; typedef P Vector; struct Triangle{ P ps[3]; }; int crossProduct(Vector v1, Vector v2){ retur</cstdio></iostream>…

AOJ 0140 - Bus Line

aoj

#include<iostream> #include<vector> //a->bまでangleの方向ではじめたときのルート //angle: 1 -> right -1 -> left std::vector<int> walk(int a, int b, int angle){ std::vector<int> res; res.push_back(a); while(a != b){ if(a == 9){ a = 5; angle = -1; }else if(a == 0 && ang</int></int></vector></iostream>…

AOJ 0065 - Trading

Ruby便利*1 last_m = {} this_m = {} while s = gets break if s == "\n" data = s.split(",").map{|e| e.to_i } last_m[data[0]] = 0 unless last_m.key?(data[0]) last_m[data[0]] += 1 end while s = gets break if s == nil data = s.split(",").map{|e|…

AOJ 0043 - Puzzle

aoj

PuzzleというかMahjangですね. #include<iostream> #include<vector> #include<cstdio> #include<cstring> int ns[10]; void stringToN(std::string s){ for(int i=1;i<=9;i++){//初期化 ns[i] = 0; } for(int i=0;i</cstring></cstdio></vector></iostream>

AOJ 0076 - Treasure Hunt II

aoj

この問題の簡単版である"Treasure Hunt"(AOJ 0016)を解いたのが2011/06/24ですから,1年半でようやく終わったことになります. 感慨深い 法線ベクトルつかって,それを長さ1にして,足し算してと当時よりも道具が増えました. 感慨深い #include<iostream> #include<cmath> #i</cmath></iostream>…

AOJ 0084 - Search Engine

重複した文字列は除かなくてよかった. words = gets.delete(",.").split(" ").select{|word| 3 <= word.size && word.size <= 6 } print words[0] for i in 1..words.size-1 print " #{words[i]}" end puts ""

AOJ 0088 - The Code A Doctor Loved

aoj

入力面倒なだけの問題. #include<iostream> #include<map> #include<sstream> std::string to_bs(int i){ std::string s = ""; while(i > 0){ s = static_cast<char>(i%2+'0') + s; i /= 2; } while(s.length() < 5){ s = '0' + s; } return s; } int main(){ std::map<char, std::string> input; std::map<std::string, char> ou</std::string,></char,></char></sstream></map></iostream>…

AOJ 0082 - Flying Jenny

aoj

はじめて8進数使った.bit処理っぽいことした. "1 2 3"みたいに出力するのが未だにきれいに書けない. #include<iostream> int main(){ int p[8], c[8] = {012121414, 014121214, 012141412, 014141212, 021214141, 041212141, 021414121, 041412121}; while(std::cin</iostream>…

AOJ 0079 - Area of Polygon

きれいに書けましたー. #include<iostream> #include<cstdio> #include<cmath> struct P{ double x, y; }; struct Triangle{ P A, B, C; }; double distance(P p1, P p2){ double dx = p1.x - p2.x, dy = p1.y - p2.y; return sqrt(dx*dx+dy*dy); } double getArea(Triangle t){ doub</cmath></cstdio></iostream>…

gets[0..-2]は怖い

gets[0..-2]で改行を削除したと思っていたら,ファイル末尾に改行が含まれていないときに死にますね. chompをつかって生きたいと思います.