码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • [博弈]Swap Game Codeforces1747C


    Alice and Bob are playing a game on an array aa of nn positive integers. Alice and Bob make alternating moves with Alice going first.

    In his/her turn, the player makes the following move:

    • If a1=0a1=0, the player loses the game, otherwise:
    • Player chooses some ii with 2≤i≤n2≤i≤n. Then player decreases the value of a1a1 by 11 and swaps a1a1 with aiai.

    Determine the winner of the game if both players play optimally.

    Input

    The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤2⋅104)(1≤t≤2⋅104)  — the number of test cases. The description of the test cases follows.

    The first line of each test case contains a single integer nn (2≤n≤105)(2≤n≤105)  — the length of the array aa.

    The second line of each test case contains nn integers a1,a2…ana1,a2…an (1≤ai≤109)(1≤ai≤109)  — the elements of the array aa.

    It is guaranteed that sum of nn over all test cases does not exceed 2⋅1052⋅105.

    Output

    For each test case, if Alice will win the game, output "Alice". Otherwise, output "Bob".

    You can output each letter in any case. For example, "alIcE", "Alice", "alice" will all be considered identical.

    Example

    input

    3

    2

    1 1

    2

    2 1

    3

    5 4 4

    output

    Bob
    Alice
    Alice

    题意: Alice和Bob轮流对数组a进行操作,Alice先手,每次操作先对a[1]减1,然后选择a[2]~a[n]中的一个位置i,将a[1]和a[i]进行交换。但轮到某人操作时a[1]等于0了,那他就输了,问最后谁获胜。

    分析: 模拟一下游戏过程可以发现,谁先把a[1]减到0谁输,那么双方肯定会尽量挑选一个最小的数放在a[1],这样对方才更有机会减到0。也就是说选数的最优策略是非常机械的,每次都选a[2]~a[n]中的最小值就行了。那么设x为a[2]~a[n]中的最小值,如果a[1]小于等于x,则Bob获胜,否则Alice获胜。

    具体代码如下:

    1. #include
    2. using namespace std;
    3. int a[100005];
    4. signed main(){
    5. int T;
    6. cin >> T;
    7. while(T--){
    8. int n;
    9. scanf("%d", &n);
    10. for(int i = 1; i <= n; i++)
    11. scanf("%d", &a[i]);
    12. int mn = *min_element(a+2, a+n+1);
    13. if(a[1] <= mn) puts("Bob");
    14. else puts("Alice");
    15. }
    16. return 0;
    17. }

  • 相关阅读:
    Java 入门练习(31 - 35)
    J2L3x 最大的优势:灵活的功能和易于扩展性
    使用cannon.js创建3D物理仿真场景
    数据链路层实验(以太网帧格式、交换机MAC地址表、广播风暴、生成树协议STP、端口聚合)
    01装饰器-【100个Python知识点】
    导数基础:概念与运算
    C语言之字符函数&字符串函数篇(1)
    【C++类型转换】4种类型转换:static_cast、reinterpret_cast、const_cast、dynamic_cast
    【数据仓库设计基础(三)】数据集市
    二十四、W5100S/W5500+RP2040树莓派Pico<PHY的状态模式控制>
  • 原文地址:https://blog.csdn.net/m0_55982600/article/details/127747287
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号