Programming

AOJ 0021 Parallelism

404 Not Found #include <cstdio> int main() { int n; scanf("%d\n", &n); for(int i = 0; i < n; i++){ double x1, y1, x2, y2, x3, y3, x4, y4; scanf("%lf %lf %lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); puts(((y1 - y2) / (x1 - x</cstdio>…

AOJ 0515 School Road

404 Not Found #include <cstdio> #include <vector> using namespace std; int a, b; vector<vector<char> > v; int dfs(int x, int y){ int _x = x + 1, _y = y + 1, m = 0; if(_x < a && y < b){ if(v[_x][y] == 0) m += dfs(_x, y); } if(x < a && _y < b){ if(v[x][_y] == 0) m += df</vector<char></vector></cstdio>…

PKU 3253 Fence Repair

3253 -- Fence Repairなんか理解に少し時間を要したけど簡単な事だった。 要求された中で最も短い板2つを足して、コストに加算 それらの長さを足して1枚の板とする その1枚の長い板と、その他の板の中から、また再び最も短い板2つを足して…(以下続く) なんだ…

PKU 2431 Expedition

2431 -- Expedition #include <cstdio> #include <vector> #include <queue> #include <algorithm> using namespace std; int main() { int N; vector<pair<int, int> > v; scanf("%d\n", &N); for(int i = 0; i < N; i++){ int x, y; scanf("%d %d\n", &x, &y); v.push_back(make_pair(x, y)); } int L, P; sc</pair<int,></algorithm></queue></vector></cstdio>…

PKU 3069 Saruman's Army

3069 -- Saruman's Army情報オリンピックだって近いのに僕はこんな程度で大丈夫なんだろうか。 いや、全然大丈夫じゃないんだが。あと半月程度でどこまで伸びられるかが勝負だけれどもそんなに急に伸びる物とも思えんしなぁ… #include <cstdio> #include <vector> #include <algorithm> </algorithm></vector></cstdio>…

PKU 3617 Best Cow Line

3617 -- Best Cow Line #include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int N; cin>>N; string s; for(int i = 0; i < N; i++){ char c; cin>>c;s += c; } string t, u; while(!s.empty()){ u = s; reverse(u.begin(), u.end()); if(u > s</algorithm></string></iostream>…

PKU 2386 Lake Counting

2386 -- Lake Countingアリ本もう一冊手に入れたので読み進めていく事にした。 #include <iostream> #include <vector> #include <string> using namespace std; bool inline validate(int x, int y, vector<string>& v){ return (0 <= x) && (x < v.size()) && (0 <= y) && (y < v[0].size());</string></string></vector></iostream>…

PKU 1051 P,MTHBGWB

1051 -- P,MTHBGWBモールス信号。 #include <iostream> #include <string> #include <map> #include <algorithm> using namespace std; inline void maketable(map<char, string>& enc, map<string, char>& dec){ const char *abc[] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-", ".-..","--","</string,></char,></algorithm></map></string></iostream>…

PKU 1068 Parencodings

1068 -- Parencodings #include <cstdio> #include <string> using namespace std; int main() { int t; scanf("%d\n", &t); for(int i = 0; i < t; i++){ int n; scanf("%d\n", &n); string s; for(int j = 0,lm = 0, m; j < n; j++){ scanf("%d", &m); s += string(m - lm,</string></cstdio>…

TopCoder SRM 486 DIV 2

197.12点。Rating: 598 -> 724 灰色なりにやっと初期の水準を回復してきた。次回でコケなければ緑に戻れるか? 250 Text Message 基本的に一発で書いて一発でテスト通して一発で提出したつもりだったのだが、案外と書くのに時間がかかってしまったせいで、200…

パソコン甲子園2010の予選問題を解く

パソコン甲子園は、私自身本来であれば出場資格のある者の筈なのだが、私の通っている高校がたまたま文系一色である故、相方を見付けられない、そもそも過去に出場したためしがないなど、種々の困難に見舞われ、今年は出場する事ができなかった。そこで、す…

TopCoder SRM 483 DIV 2

DIV2においては500点問題が無茶苦茶落ちる回で、うっかりDIV2の1位の人と同じ部屋になったりと個人的にも踏んだり蹴ったりだったが、DIV1においてはtargetのPetrが全問System Test Failedしたり酷い事になっていて話題だったらしい。自分のレートは一応ちょ…

AOJ 0057 The Number of Area

404 Not Found #include <cstdio> int main() { int n; while(~scanf("%d\n", &n)) printf("%d\n", (n * n + n + 2) / 2); return 0; } just implemented a formula that I found on the internet</cstdio>

AOJ 0074 Videotape

404 Not Found #include <cstdio> int main() { int l, m, n; while(~scanf("%d %d %d", &l, &m, &n), ~l && ~m && ~n){ long long total = l * 60LL * 60 + m * 60 + n, remaining = 120 * 60 - total; printf("%02lld:%02lld:%02lld\n", remaining / 60 / 60, rema</cstdio>…

AOJ 0071 Bombs Chain

404 Not Found #include <cstdio> #include <vector> #include <queue> using namespace std; typedef struct {int x, y;} p; char m[8][9]; inline bool valid(int n){return 0 <= n && n < 8;} inline void addqueue(queue<p>& q, int x, int y){ if(valid(x) && valid(y)) if(m[y][x</p></queue></vector></cstdio>…

AOJ 0085 Joseph's Potato

404 Not Found #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; while(scanf("%d %d\n", &n, &m), n && m){ vector<int> v; for(int i = 1; i <= n; i++) v.push_back(i); vector<int>::iterator it = v.begin(); while(1 < v.size()){ fo</int></int></algorithm></vector></cstdio>…

AOJ 0085 Joseph's Potato

404 Not Found #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; while(scanf("%d %d\n", &n, &m), n && m){ vector<int> v; for(int i = 1; i <= n; i++) v.push_back(i); vector<int>::iterator it = v.begin(); while(1 < v.size()){ fo</int></int></algorithm></vector></cstdio>…

AOJ 0056 Goldbach's Conjecture

404 Not Found #include <cstdio> int main() { int n; char prime[50001]; for(int i = 0; i <= 50000; i++) prime[i] = 1; prime[0] = 0; prime[1] = 0; for(int i = 2; i <= 50000; i++){ if(!prime[i]) continue; for(int j = i + i; j <= 50000; j += i) prime[</cstdio>…

AOJ 0044 Prime Number II

404 Not Found #include <cstdio> inline int isprime(int n){ for(int i = 2; i <= n / 2; i++){ if(!(n % i)) return 0; } return 1; } int main() { int n; while(~scanf("%d\n", &n)){ for(int i = n - 1; 0 <= i; i--){ if(isprime(i)){ printf("%d ", i); brea</cstdio>…

AOJ 0063 Palindrome

404 Not Found #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string s, t; int cnt = 0; while(cin>>s){ t = s; reverse(t.begin(), t.end()); cnt += s == t; } cout<</algorithm></string></iostream>

AOJ 0502 Dice

404 Not Found #include <iostream> #include <string> using namespace std; class Dice { public: int top, bottom, west, east, south, north; Dice(){ top = 1;bottom = 6; west = 4;east = 3; south = 2;north = 5; } void North(){ int tmp = top; top = south; south = </string></iostream>…

AOJ 0014 Integral

404 Not Found #include <cstdio> int main() { int d; while(~scanf("%d\n", &d)){ long long total = 0; for(int i = d; i < 600; i += d) total += (long long)i * i * d; printf("%lld\n", total); } return 0; }</cstdio>

AOJ 0019 Factorial

404 Not Found #include <cstdio> int main() { int n; scanf("%d\n", &n); long long m = n; while(--n) m *= n; printf("%lld\n", m); return 0; }</cstdio>

AOJ 0100 Sale Result

404 Not Found #include <cstdio> #include <vector> using namespace std; int main() { long long n; while(scanf("%Ld\n", &n), n){ vector<pair<long long, long long> > v; for(long long i = 0; i < n; i++){ long long p, q, r, f = 1; scanf("%Ld %Ld %Ld\n", &p, &q, &r); for(long long j = 0;</pair<long></vector></cstdio>…

AOJ 0500 Card Game

404 Not Found #include <cstdio> int main() { int n; while(scanf("%d\n", &n), n){ int scr_a = 0, scr_b = 0; for(int i = 0; i < n; i++){ int cur_scr_a, cur_scr_b; scanf("%d %d\n", &cur_scr_a, &cur_scr_b); if(cur_scr_a == cur_scr_b){ scr_a += cur_scr</cstdio>…

SRM 481 DIV 2

また0点…どんどん緑コーダーが遠ざかっていく… しかし、さっき手元でデバッグしていたら、本当の恐怖はそんなモンではなかった… 250点問題(誤答) #include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #in</memory></iostream></set></utility></map></cfloat></climits></cmath></cstdlib></cstdio>…

PKU 1012 Joseph

1012 -- Joseph #include <cstdio> int main() { int k , _n; int r[14]; for(int i = 0; i < 14; i++) r[i] = 0; while(scanf("%d", &k), k){ if(!r[k]){ _n = k * 2; for(int i = k; ; i++){ int n = _n, p = 0; while(n != k){ p = (p + i) % n--; if(p < k) goto</cstdio>…

最大の4つ子素数を求める

#include <cstdio> int main() { int n; scanf("%d\n", &n); if(!n) return 0; char *c = new char[n + 1]; for(int i = 0; i <= n; i++) c[i] = 1; c[0] = c[1] = 0; for(int i = 2; i <= n; i++){ if(!c[i]) continue; for(int j = i + i; j <= n; j += i) c[j] = </cstdio>…

TopCoder SRM 480で大敗北

250点問題と500点問題そこそこの速度でサブミットしてよっしゃあって思ってたら2問ともチャレンジされてしかも成功された。 0点だった。レートがグレーになってしまった。ショックだ。一応自分の誤答をはってみる。 250 #include <cstdio> #include <cstdlib> #include <cmath> #incl</cmath></cstdlib></cstdio>…

アルゴリズムC++ P.16 練習問題 1

#include <iostream> #include <algorithm> using namespace std; int gcd_new(int u, int v) { while(u > 0){ if(u < v) swap(u, v); u %= v; } return v; } int gcd_old(int u, int v) { int t; while(u > 0){ if(u < v) swap(u, v); u -= v; } return v; } int main() { int x,</algorithm></iostream>…