Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Who wins if both participants play optimally? Alice and Bob would like to play several games, so you should determine the winner in each game. Input Output For each game, print Alice if Alice wins this game and Bob otherwise. Example inputCopy 4 0 3 3 3 3 4 4 4 outputCopy Bob Alice Bob Alice 题意: 当前在n位置,每一次可以向左走1,2,或者k步,最左的位置是0,不能走到0之后, 二人博弈问题,谁没发走谁输,问先手必赢还是后手必赢。 思路: 首先确定的是 0位置是必数位置,因为 1 2 和k这三个位置可以一步就走到0位置,所以这3个位置是必赢位置,以此规律,我们可以递推出sg函数。 #include <iostream> #include <cstdio>