题解 | 甜蜜的博弈
甜蜜的博弈
https://www.nowcoder.com/practice/d3934f2d05624c8fa1a748ef225d0460
using System;
using System.Collections.Generic;
class Program {
static void Main() {
// 定义小于12时的必败态集合
HashSet<int> lose_small = new HashSet<int> { 3, 6, 9, 11 };
// 读取测试用例数量
int t = int.Parse(Console.ReadLine());
for (int i = 0; i < t; i++) {
int n = int.Parse(Console.ReadLine());
if (n < 12) {
// 小数字:查表
if (lose_small.Contains(n)) {
Console.WriteLine("Bob");
} else {
Console.WriteLine("Alice");
}
} else {
// 大数字:判断奇偶
if (n % 2 != 0) {
Console.WriteLine("Bob");
} else {
Console.WriteLine("Alice");
}
}
}
}
}
//小于 12:只有 3、6、9、11 是 Bob 赢
//大于等于 12:奇数 Bob,偶数 Alice

查看5道真题和解析