当前位置:网站首页>數學知識:臺階-Nim遊戲—博弈論
數學知識:臺階-Nim遊戲—博弈論
2022-07-03 01:26:00 【奮鬥吧!騷年!】
題目:AcWing 892. 臺階-Nim遊戲
現在,有一個 n 級臺階的樓梯,每級臺階上都有若幹個石子,其中第 i 級臺階上有 ai 個石子(i≥1)。
兩比特玩家輪流操作,每次操作可以從任意一級臺階上拿若幹個石子放到下一級臺階中(不能不拿)。
已經拿到地面上的石子不能再拿,最後無法進行操作的人視為失敗。
問如果兩人都采用最優策略,先手是否必勝。
輸入格式
第一行包含整數 n。
第二行包含 n 個整數,其中第 i 個整數錶示第 i 級臺階上的石子數 ai。
輸出格式
如果先手方必勝,則輸出 Yes。
否則,輸出 No。
數據範圍
1≤n≤105,
1≤ai≤109
輸入樣例:
3
2 1 3
輸出樣例:
Yes
題目分析:
這一題與上一題做法差不多
a1^a3^a5…^an!=0則先手必贏
先手必贏策略:
如果拿偶數臺階,則將拿出來的放在下一臺階,則會保持奇數臺階保持不變。
如果拿奇數臺階,則异或不為0,則操作讓其异或變為0。
反之,如果异或為0,則後手贏。
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int res=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(i%2)res^=x;
}
if(res)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
边栏推荐
- Cut point of undirected graph
- 不登陆或者登录解决oracle数据库账号被锁定。
- The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
- SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
- 12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
- Database SQL language 01 where condition
- tp6快速安装使用MongoDB实现增删改查
- 1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
- 按鍵精靈打怪學習-多線程後臺坐標識別
- Work experience of a hard pressed programmer
猜你喜欢

Leetcode 6103 - minimum fraction to delete an edge from the tree

给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】

Embrace the safety concept of platform delivery

leetcode 2097 — 合法重新排列数对
![[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)](/img/ca/1d2473ae51c59b84864352eb17de94.jpg)
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)

Arduino DY-SV17F自动语音播报

Arduino dy-sv17f automatic voice broadcast

Matlab Doppler effect produces vibration signal and processing

寻找标杆战友 | 百万级实时数据平台,终身免费使用

用Go+绘制爱心给心爱的她表白
随机推荐
Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
对非ts/js文件模块进行类型扩充
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
MySQL
Key wizard play strange learning - multithreaded background coordinate recognition
MySQL foundation 07-dcl
每日一题之干草堆的移动
Detailed explanation of Q-learning examples of reinforcement learning
一比特苦逼程序員的找工作經曆
按键精灵打怪学习-自动回城路线的判断
Assets, vulnerabilities, threats and events of the four elements of safe operation
Tp6 fast installation uses mongodb to add, delete, modify and check
力扣 204. 计数质数
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
MySQL foundation 06 DDL
Excel if formula determines whether the two columns are the same
The difference between tail -f, tail -f and tail
Meituan dynamic thread pool practice ideas, open source
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0