算法基础之Nim游戏

Nim游戏

  • 核心思想:博弈论

    • 结论:将所有堆的石子数全部异或起来 得到的结果
    • 若为1 则先手必胜 若为0 则先手必败
cpp 复制代码
  #include <iostream>
  #include <cstring>
  #include <algorithm>
  
  using namespace std;
  const int N = 100010;
  
  int a[N];
  int n;
  
  int main()
  {
      cin>>n;
      int x;
      cin>>x;
      int res = x;
      for(int i=1;i<n;i++) cin>>x, res ^= x;
      
      if(res) puts("Yes");
      else puts("No");
  }
相关推荐
杜子不疼.8 小时前
【C++ AI 大模型接入 SDK】 - DeepSeek 模型接入(上)
开发语言·c++·chatgpt
石山代码9 小时前
C++ 内存分区 堆区
java·开发语言·c++
心中有国也有家9 小时前
cann-recipes-infer:昇腾 NPU 推理的“菜谱集合”
经验分享·笔记·学习·算法
绝知此事9 小时前
【算法突围 01】线性结构与哈希表:后端开发的收纳术
java·数据结构·算法·面试·jdk·散列表
碧海银沙音频科技研究院9 小时前
通话AEC与语音识别AEC的软硬回采链路
深度学习·算法·语音识别
csdn_aspnet10 小时前
Python 算法快闪 LeetCode 编号 70 - 爬楼梯
python·算法·leetcode·职场和发展
richard_yuu10 小时前
鸿蒙治愈游戏模块实战|四大轻量解压游戏、ArkTS动画交互与低功耗落地
游戏·交互·harmonyos
魔法阵维护师11 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#
张小姐的猫11 小时前
【Linux】多线程 —— 线程互斥
linux·运维·服务器·c++