题解 | 甜蜜的博弈

甜蜜的博弈

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

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务