首页 > 代码库 > Gym - 100952G (博弈)
Gym - 100952G (博弈)
Statements
Alice and Bob play the following game. They choose a number N to play with. The rules are as follows:
- They write each number from 1 to N on a paper and put all these papers in a jar.
- Alice plays first, and the two players alternate.
- In his/her turn, a player can select any available number M and remove its divisors including M.
- The person who cannot make a move in his/her turn wins the game.
Assuming both players play optimally, you are asked the following question: who wins the game?
Input
The first line contains the number of test cases T (1 ?≤? T ?≤? 20). Each of the next T lines contains an integer (1 ?≤? N ?≤? 1,000,000,000).
Output
Output T lines, one for each test case, containing Alice if Alice wins the game, or Bob otherwise.
Example
2
5
1
Alice
Bob
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 5 int main(){ 6 int T; scanf("%d", &T); 7 while(T--){ 8 int n; 9 scanf("%d", &n); 10 if(n>1) printf("Alice\n"); 11 else printf("Bob\n"); 12 } 13 return 0; 14 } 15 /* 16 题意:有一个容器里装着 n个数, 17 A和B每次任意说一个数m, 18 那么他要拿走容器里m的所有因子, 19 如果谁拿空了容器,那么他输了, 20 求先手赢还是后手赢 21 22 思路:只有1是后手赢, 23 因为1只能拿一次, 24 大于1的情况, 25 假设a和b都不是聪明的, 26 假设先手出x,后手出y 27 结果是后手赢, 28 那么现在a和b都是聪明的, 29 先手可以直接出x*y( 30 即先手可以复制后手的操作, 31 先手的操作可以包括后手的操作), 32 则可以赢后手, 33 所以大于1的情况一定是先手赢 34 */
Gym - 100952G (博弈)