2020 cattle off winter training camp algorithm basis 5.E - Enjoy the game [Game]

Topic Portal


Title Description

Taurus team three players in the training apart from his own mouth Hu will be some questions as usual puzzle game. One day cattle Coke came up with a game to play with two other players, rules of the game are as follows:

  • A total initial nn card card
  • Just get a minimum first step to bring a card, bring it up to n-1 cards.
  • Then each step, the two sides at least bring a brand, get the most equal to the number of cards on the card to get the other side of the step.
  • Who took the last card will win the game.

You, as a spectator, watching them playing very happy, want to participate in this game, who will take a risk to win.


Enter a description:

The input data includes an integer n ( 2 n 1 0 18 ) n (2 \ leq n \ leq 10 ^ {18}) , indicates the number of a card's initial card.


Output Description:

If you have the upper hand winning strategy, output Bob, otherwise the output Alice.


Entry

2


Export

Alice


Explanation

The upper hand must take a card, then he took the flip another card, the game ends.


answer

  • Firstly Truth: but those who 2 n 2^n is the flip win
  • Look at pictures, we consider only just get yourself can winHere Insert Picture Description
  • n = 1 Victory n = 1: win
  • n = 2 defeat n = 2: defeat , only their own to take a, take a partner, then GG
  • n = 3 Victory n = 3: wins , get yourself a, make each other reach n = 2 n=2 的必败点
  • n = 4 defeat n=4:败 ,如图红色箭头所指两种情况,都是必败状态
  • n = 5 n=5:胜 ,拿 1 1 个,令对方到达 n = 4 n=4 的必败点
  • n = 6 n=6:胜 ,拿 2 2 个,令对方到达 n = 4 n=4 的必败点
  • n = 7 n=7:胜 ,拿 3 3 个,令对方到达 n = 4 n=4 的必败点
  • n = 8 n=8:败 ,无论怎么拿,都会达到对方的必胜点。
  • 由此我们可以发现,若当前必败点为 x x ,距离下一个必败点的距离,就是 2 x 2x 位置
  • 也就是必败点为: 2 4 8 16 32 . . . 2 n 2,4,8,16,32,...,2^n

AC-Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;    while(cin >> n){
        cout << ((n&(-n)) == n ? "Alice" : "Bob") << endl;
    }
    return 0;
}
Published 179 original articles · won praise 110 · views 10000 +

Guess you like

Origin blog.csdn.net/Q_1849805767/article/details/104300542