当前位置:网站首页>數學知識:臺階-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;
}
边栏推荐
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
- Key wizard hit strange learning - automatic path finding back to hit strange points
- Makefile中wildcard、patsubst、notdir的含义
- 无向图的割点
- Button wizard play strange learning - automatic return to the city route judgment
- R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
- The meaning of wildcard, patsubst and notdir in makefile
- Delete duplicate elements in the ordered linked list -ii
- Daily topic: movement of haystack
- Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
猜你喜欢
![[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core](/img/fb/c371ffaa9614c6f2fd581ba89eb2ab.png)
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core

Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man

Machine learning terminology

Cut point of undirected graph
![[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge](/img/ed/23331d939c9338760e426d368bfd5f.png)
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge

Using tensorboard to visualize the model, data and training process

JS inheritance and prototype chain

一位苦逼程序员的找工作经历

有向图的强连通分量

每日一题之干草堆的移动
随机推荐
Look at how clothing enterprises take advantage of the epidemic
Key wizard hit strange learning - automatic path finding back to hit strange points
对非ts/js文件模块进行类型扩充
Is there a handling charge for spot gold investment
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
How is the mask effect achieved in the LPL ban/pick selection stage?
uniapp组件-uni-notice-bar通告栏
[untitled]
关于Fibonacci数列
Telephone network problems
[C language] detailed explanation of pointer and array written test questions
Mongodb common commands of mongodb series
Matlab Doppler effect produces vibration signal and processing
tp6快速安装使用MongoDB实现增删改查
C#应用程序界面开发基础——窗体控制(4)——选择类控件
按键精灵打怪学习-自动寻路回打怪点
Kivy tutorial how to create drop-down lists in Kivy
Thinkphp+redis realizes simple lottery
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
[system analyst's road] Chapter V double disk software engineering (development model development method)