算法基础之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");
  }
相关推荐
kisshyshy10 小时前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
众少成多积小致巨12 小时前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
猿人谷17 小时前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
jump_jump18 小时前
为了重玩金庸群侠传,我研究了一下 Ruffle 怎么复活 Flash
游戏·rust·github
复杂网络18 小时前
Stable Diffusion 视觉大模型微调技术深度调研
算法
复杂网络19 小时前
基于 Stable Diffusion 架构的视觉大模型代表性工作与原理深度解析
算法
MrZhao40019 小时前
Agent Loop 如何用 Hook 扩展:权限、日志与工具拦截
算法
MrZhao40019 小时前
Agent 为什么需要 Skills:别把所有知识都塞进 system prompt
算法
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
JieE2122 天前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法