http://acm.hdu.edu.cn/showproblem.php?pid=4315
Test instructions: There are n people to move to the coordinates of 0, they have a position a[i], of which the most close to 0 of the K-person is king, when moving in the back of the people can not cross the front of the people, first to send King to 0 of the people wins.
Idea: Ladder game. The n personal 22 pairs, forming a group, namely A[i] and A[i+1] is a group, a[i+2] and A[i+3] is a group, a[i] and a[i+1] distance as the ladder game of the odd-order value, a[i+1] and a[i+2] distance as even order (do not consider). First k=1 time to win. Even in the case, 22 adjacent is a must-fail state, because if the initiator moves in front, the hand can certainly make the situation or 22 adjacent, and then the first move the person in front of king, the hand as long as the king moved to the end. If n is odd, the a[1] goes to the end is the even number of cases. So if K is the second person and n is odd, the first person can only move to the 1 position, otherwise k can move directly to 0, so a[1] to 1.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 #defineN 10105 intId[n];6 intC[n];7 8 intMain () {9 intN, K;Ten while(SCANF ("%d%d", &n, &k)! =EOF) { One for(inti =1; I <= N; i++) scanf ("%d", id+i); A if(k = =1) { -Puts"Alice"); -}Else { the intAns =0; - if(N &1&& k = =2) id[1]--; - for(inti =2+ (N &1); I <= N; i + =2) -Ans ^= (id[i]-id[i-1] -1); + if(N &1) Ans ^= id[1]; - if(ANS) puts ("Alice"); + ElsePuts"Bob"); A } at } - return 0; -}
HDU 4315:climbing the Hill (ladder game)