This problem requires us to find two non-negative numbers m1 and m2 that satisfying n1*m1 + n2*m2 = nand minimize the cost c = c1*m1 + c2*m2. First, we can use extended Euclid's algorithm to find m1' and m2' that give n1*m1' + n2*m2' = gwhere g
Let g(n) denote the n'th number that satifies f(k) > f(k-1). We can know that g(0) = 1, g(1) = 2, g(2) = 4, ... From the definition of g(n), we can know that all the values of f(k) where k belongs to the range of [g(n-1), g(n)) is n. Since
This is the hardest problem ever since in this book. After some thinking, I realized that this problem can be solved with backtracking. After some more thinking, I realized that we should backtrack the cipher, i.e., the decrypt table along with the
Imagine that a chessboard with black and white squares. If a bishop is on a white square, can it attack bishops on black squares? No.So you can divide the chessboard into two independent ones. Then rotate each board for PI/4 and now the diagonal
類比題,根據題目描述的內容直接寫程式就可以。需要注意的是非法輸入的情況:對於a==b或是a和b在同一堆的輸入命令直接忽略。 返回 Volume I 索引返回總索引 // 101_The_Blocks_Problem.cpp : Defines the entry point for the console application.//#include <set>#include <map>#include <list>#include
此題本身不難,因為對於輸入,只有6種可能的組合。直接用暴力法枚舉所有可能就可以了。主要的問題在於保證輸出所有最優解中字典序最少的一個。 返回 Volume I 索引返回總索引 // 102_Ecological_Bin_Packing.cpp : Defines the entry point for the console application.//#include <set>#include <map>#include <list>#include
I originally used the straight forward method and got a RT of 1.250s. I believe that if I were using Java, I would get a TL. Thus, I switch to the method of precomputing all the cycle-lengths in range (0, 1000000). Let al, al-1, ..., a1 donate the
This problem is much easier than its brother, "843 - Crypt Kicker". Just find the key line and get the translate table from it will do all the job. I generate a "signature" for the key line to make the search easier. By the way, pay attention to
I solve this problem in a manner that seems not straight forward. I let the fragments to "vote" on each bit if it is '0' or '1'. Specifically, for each fragment, it is either the head or tail of the file. We let it to vote as both. Thus, for each