首页 > 代码库 > Gym - 100952G
Gym - 100952G
G. The jar of divisors
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?
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 T lines, one for each test case, containing Alice if Alice wins the game, or Bob otherwise.
2
5
1
Alice
Bob
博弈论题目。1就是Bob赢否则就是Alice赢,不知道怎么来的,算了8个发现只有1是Bob赢就这样写了,没想到还真过了。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <algorithm> 5 #define ll long long 6 using namespace std; 7 int main(){ 8 int t,n; 9 cin>>t; 10 while(t--){ 11 cin>>n; 12 if(n == 1){ 13 cout << "Bob\n"; 14 }else cout << "Alice\n"; 15 } 16 return 0; 17 }
Gym - 100952G