0w1

Ad hoc

CFR 610 C. Harmony Analysis ( Ad hoc )

Problem - C - Codeforces 這題需要的是一點直覺,或說是靈感。要發現其實只要遞迴構造左上右上左下都相同的,而右下正負相反,初始是n = 0時為+。 #include <bits/stdc++.h> using namespace std; const int MAXK = 9 + 1; int a[ 1 << MAXK ][ 1 << MAXK ]; int main(){ i</bits/stdc++.h>…

CFR 297 1A. Parity Game ( Ad hoc )

Problem - 297A - Codeforces 顯然1的數量最多只會變多一次,而且是當且僅當原本1的數量是奇數。排除掉那些情況後觀察一下就會發現怎樣都可以使a變成b的。 #include <bits/stdc++.h> using namespace std; const int MAXS = 1e3 + 3; string a, b; int countOne( const stri</bits/stdc++.h>…

CFR 659 D. Bicycle Race ( Adhoc )

Problem - D - Codeforces よく考えると前の方向と今の方向としか関わらない。本番中は難しく考えすぎて偶数奇数まで思考が飛んでタイムオーバー。 レーティングが元から低いから落ちてないし逆に上がった。 次は書き出す前に自信を持って、合ってると確信し…

CFR 404 C. Restore Graph ( Adhoc )

Problem - 404C - Codeforces The vertex i with dis[ i ] = 0 will be the origin, and if it doesn't exist, or multiple 0 distance vertices exist, there will be no solution. Otherwise iterate through all distances from smaller to larger and ex…

CFR 330 B. Road Construction ( Graph Adhoc )

Problem - 330B - Codeforces There are n vertices and at most n / 2 - 1 edges. Easy to see that there will be at least one vertex with 0 degree. #include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 3; const int MAXM = MAXN / 2; int n, m; i</bits/stdc++.h>…

CFR 658 C. Bear and Forgotten Tree 3 ( Adhoc Tree )

Problem - C - Codeforces 細かいケースが多く、割と面倒くさい。 でもちゃんと考えてたら、実は簡単。 #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, d, h; void solve(){ if( n < h + 1 ) return (void)puts("-1"); // 一直線でやって</bits/stdc++.h>…

CFR 300 B. Coach ( DFS )

Problem - 300B - Codeforces 暴力でやるだけ。実装が下手。 つまらないミスで時間を溶かした。 #include <bits/stdc++.h> using namespace std; const int MAXN = 48 + 2; const int MAXM = MAXN * MAXN / 2; int n, m; vector< int > G[ MAXN ]; struct UnionFind{ int fa</bits/stdc++.h>…

CFR 546 C. Soldier and Cards ( 狀態記錄 )

http://codeforces.com/contest/546/problem/C 水。 #include <bits/stdc++.h> using namespace std; const int MAXN = 10 + 2; int n; deque< int > dq1, dq2; typedef pair< deque< int >, deque< int > > pdq; set< pdq > vis; void solve(){ int rnd_cnt = 0; while( !d</bits/stdc++.h>…

TOJ 275 同學會 ( Adhoc )

http://sprout.tw/oj/pro/275/ 這題雖然看起來很簡單,卻要想清楚很多細節才能寫好。最重要的關鍵是要發現如何做才能快速地發現那個團體中最後一個人。如果我們對每個團體紀錄 id的總和,剩下的人數,每次減少一個人就從 id總和減去它的 id,就能夠在刪除某…

JOI 11 本選 Card Game is Fun ( Adhoc )

Card Game is Fun | Aizu Online Judge Aに対して全てのindexからすぐに次の数字にジャンプできる様にする、O( a ^ 2 )。そうするとBでどこから始めるのか枚挙し、いちいちどこまでいけるかをクエリしてもO( a * b )になる。 #include <bits/stdc++.h> using namespace std;</bits/stdc++.h>…

ABC 27 D - ロボット ( Adhoc )

D: ロボット - AtCoder Beginner Contest 027 | AtCoder 各Mについて右、左のどちらにすすむかをいちいち決めるとやばい。そもそもそれを早くする方法もあまり考えられない。しかしよく考えると、右に移動と決めたら、移動しないと比べて全体的に 右にある +…

CFR 633 D. Fibonacci-ish ( Ad hoc )

Problem - D - Codeforces It is easy to realize that once the first two elements are determined, the rest in the Fibonacci sequence are determined as well. Another important property is that Fibonacci sequence expands exponentially, and giv…

UVA 10905 Children's Game ( Ad hoc )

UVa Online Judge 挺有趣的一道題。一開始很直覺的直接比較字典序,WA了一波才想到問題在於長度相異的時候比較時,像是 cmp( 2, 27 ) 和 cmp( 2, 21 ) 是不同的,前者要回傳 false使成為 272,而後者要回傳 true使成為 221才會對。所以這時候應該要直接比較 …

UVA 10970 Big Chocolate ( 數學水題 )

UVa Online Judge 給一個 n * m的巧克力,問最少要切幾刀才能全部變成 1 * 1的巧克力,一次只能切在一塊的整數線上。 直覺上把巧克力變成 n條 m個巧克力的條或 m條 n個巧克力的條不會比縱橫亂切差,簡化一下代數又發現這兩種都必須要切 n * m - 1次。。如果…

CF 579D "Or" Game ( Ad hoc )

Problem - D - Codeforces We should notice that it is necessary to somehow maximize the largest number, so all the x should be multiplied on the same number, otherwise the most significant digit could be pushed even further. However we cann…

Little interesting logic problem

Problem statement: 100 people are on the same field, and each of them wears a hat with a color ( only 2 kinds of colors ). Each of them can see all the distribution of the colors except his/her own. Now each person has to guess the color o…