2012-12-25から1日間の記事一覧

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>…