情形一:最后取光者胜
玩过巴什博弈类型之一的取石子的人都知道给你n个石子,两个人轮流取,规定每人每次至少取一个最多取m个,那么第一种情况是说最后取光者胜,并且假设双方都采用最优策略。
分析,如果留给对手最后是m+1个那么对手至多取m个,最少取1个,那么最后取玩的一定是自己,那么如果在每次取之前对手都面对着(m+1)的倍数,即对手无论接下来取多少,自己总能补齐使两个人的取的石子数目只和为(m+1)最后对手就会面临m+1个石子的情况即自己一定会最后拿完
即如果自己是先手,那么如果n%(m+1)==0即自己面临(m+1)倍数的情形,并在双方均采用最佳策略的情况下一定会输
如果n%(m+1)!=0那么自己就取走n%(m+1)个,使对手面临(m+1)的倍数,即最后对手一定会输
情形二:最后取光者败
如果最后你的对手取的时候只剩下一个石子,由于至少取一个,那么你的对手一定是取光的,那么即对手一定输,即n-1个石子谁先取完谁就赢了,那么参照情形一如果自己先手,并且(n-1)%(m+1)==0,那么自己一定会输否则对手一定输
特殊情形:
如果m>=n
就是说可以一次取走,对于情形一来说先手一定赢,,如果此时n=1那么对于情形二来说先手必输,否则后手必输。
Stone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2144 Accepted Submission(s): 1511
Problem Description
Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a white board. Tang writes first, then Jiang, then again Tang, etc... Moreover, assuming that the number written in the previous round is X, the next person who plays should write a number Y such that 1 <= Y - X <= k. The person who writes a number no smaller than N first will lose the game. Note that in the first round, Tang can write a number only within range [1, k] (both inclusive). You can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.
Input
There are multiple test cases. For each test case, there will be one line of input having two integers N (0 < N <= 10^8) and k (0 < k <= 100). Input terminates when both N and k are zero.