Reprinted please indicate the source, thank youHttp://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove
Shen Niu Cao Qin Xiang's thesis: Starting from "K times dynamic subtraction game" to explore a class of combined Game Problems
I don't even understand it ....
The number of stones obtained by each person cannot exceed the number of stones obtained by another person in the previous round * k
Give N, K to determine that the first hand wins and seek the first step
Game questions
The thinking process of this question is very meaningful.
When k = 1, we can see that the bid is 2 ^ I splits N into binary values, and then removes the last one first. then, the other party will not be able to remove the higher 1, and the other party will at least be able to remove the last 1 after obtaining the other party, which will never end.
When K = 2, the defeat is a series of Fibonacci. Using the idea that "first hand removes the last 1, then the latter hand will not be able to remove the Higher Order 1, resulting in incomplete", the Fibonacci series has a very good nature: any integer can be written as the sum of non-adjacent items in the Fibonacci series, so n is written in this form. First, the last 1 is taken, and the number that the other party can take is this number * 2, it is less than 1 of the 2-digit height, so it cannot be obtained.
When K is used, find a way to construct a series, and write N as the sum of some items in the series, so that the two adjacent multiples of the obtained items are greater than K. Therefore, each time the last 1 is removed, the above conditions are met. Set this series to have been constructed with the I entry. The I entry is a [I], and the first I entry can be perfectly matched with 1 .. B [I] encoding causes any two multiples of each encoding> K.
A [I + 1] = B [I] + 1; this is obvious because B [I] + 1 cannot be constructed and only one new expression can be created.
Then calculate B [I + 1]. Since a [I + 1] is used, the next item can only be a [T] at most so that a [T] * k <A [I + 1]
B [I] = B [T] + A [I + 1]
Then, determine whether N is in this series.
If yes, the first hand will be defeated. Otherwise, the items in Series A will be removed to construct the decomposition of N, and the last one will be.
The above conversion from x ox: http://hi.baidu.com/lccycc_acm/item/a6f0dd0ec5c44a39f3eafcd3
Make some explanations: first a [I] = B [I-1] + 1; B [I-1] is by a [0]… A [I-1] composition of the maximum number, then B [I-1] + 1 can not use a [0]... A [I-1] composition.
Then, if (a [J] * k <A [I])
B [I] = B [J] + A [I]; Else
B [I] = A [I];
B [J] is required, indicating a [0]... A [I] composition, it is obviously to use a [I], otherwise it will not become B [I-1], since the use of a [I], however, the adjacent multiples must be greater than K. Find the largest J
If a [J] * k <A [I] meets the condition, a [0]… The maximum number that a [J] can consist of, plus a [I], then the latter indicates that the current item cannot be combined with the previous item, then the maximum number can only be itself
# Include <iostream> # include <cstdio> # include <cstring> # define n 2000000 using namespace STD; int A [n], B [N]; int N, K, t, CAS = 0; int main () {scanf ("% d", & T); While (t --) {scanf ("% d", & N, & K); int I = 0, j = 0; A [0] = B [0] = 1; while (A [I] <n) {I ++; A [I] = B [I-1] + 1; while (A [J + 1] * k <A [I]) J ++; if (A [J] * k <A [I]) B [I] = B [J] + A [I]; elseb [I] = A [I];} printf ("case % d:", ++ CAS); if (a [I] = N) puts ("lose"); else {int ans; while (N) {If (n> = A [I]) {n-= A [I]; ans = A [I];} I --;} printf ("% d \ n", ANS) ;}} return 0 ;}