Game with Board
题面翻译
Alice 和 Bob 玩游戏,他们有一块黑板。最初,有 \(n\) 个整数 \(1\)。Alice 和 Bob 轮流操作,Alice 先手。
轮到时,玩家必须在棋盘上选择几个(至少两个)相等的整数,擦除它们,然后写一个等于它们总和的新整数。
如果玩家不能移动(棋盘上的所有整数都不同),该玩家将赢得游戏。
如果两名选手都发挥最佳,则确定谁获胜。
题目描述
Alice and Bob play a game. They have a blackboard; initially, there are $ n $ integers written on it, and each integer is equal to $ 1 $ .
Alice and Bob take turns; Alice goes first. On their turn, the player has to choose several (at least two) equal integers on the board, wipe them and write a new integer which is equal to their sum.
For example, if the board currently contains integers $ {1, 1, 2, 2, 2, 3} $ , then the following moves are possible:
- choose two integers equal to $ 1 $ , wipe them and write an integer $ 2 $ , then the board becomes $ {2, 2, 2, 2, 3} $ ;
- choose two integers equal to $ 2 $ , wipe them and write an integer $ 4 $ , then the board becomes $ {1, 1, 2, 3, 4} $ ;
- choose three integers equal to $ 2 $ , wipe them and write an integer $ 6 $ , then the board becomes $ {1, 1, 3, 6} $ .
If a player cannot make a move (all integers on the board are different), that player wins the game.
Determine who wins if both players play optimally.
输入格式
The first line contains one integer $ t $ ( $ 1 \le t \le 99 $ ) — the number of test cases.
Each test case consists of one line containing one integer $ n $ ( $ 2 \le n \le 100 $ ) — the number of integers equal to $ 1 $ on the board.
输出格式
For each test case, print Alice if Alice wins when both players play optimally. Otherwise, print Bob.
样例 #1
样例输入 #1
2
3
6
样例输出 #1
Bob
Alice
分析
因为A先走, A有主动权, 我们看A能不能找到一个策略让自己必赢, 如果有那么A赢, 如果没有那么B赢, 所以这道题的理解很容易出错, 不明白题目所说的 "两人均发挥最佳" 是什么意思
A如果要赢, 就要让B无论如何选A都是赢的, 那么A可以在第一步的时候构造出 1 1 n-2 的情况, 然后B不得不选两个1去合, 合完之后 2 和 n-2 不一样, 肯定是A赢.
要让 2 和 n-2 不一样, n 要大于等于5, 那么也就是说 n 大于等于5的时候, A必赢
当n是2到4的时候, 推一下就知道无论A怎么选, 都是B赢
综上就可以总结出来了
感觉是一个好大的坑啊妈的
代码
感觉这个代码写得好屈辱啊妈的
#include <iostream>
using namespace std;
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while(t--)
{
int n; cin >> n;
if(n >= 5) cout << "Alice\n";
else cout << "Bob\n";
}
}