当前位置:网站首页>數學知識:臺階-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;
}
边栏推荐
- Kivy教程大全之如何在 Kivy 中创建下拉列表
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 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
- 【FH-GFSK】FH-GFSK信号分析与盲解调研究
- Type expansion of non ts/js file modules
- [fh-gfsk] fh-gfsk signal analysis and blind demodulation research
- 【FPGA教程案例5】基于vivado核的ROM设计与实现
- Swiftui component Encyclopedia: using scenekit and swiftui to build interactive 3D pie charts (tutorial with source code)
- MySQL - database query - condition query
- 2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
猜你喜欢
![[Androd] Gradle 使用技巧之模块依赖替换](/img/5f/968db696932f155a8c4a45f67135ac.png)
[Androd] Gradle 使用技巧之模块依赖替换

Cut point of undirected graph

Leetcode 2097 - Legal rearrangement of pairs
![[androd] module dependency replacement of gradle's usage skills](/img/5f/968db696932f155a8c4a45f67135ac.png)
[androd] module dependency replacement of gradle's usage skills

机器学习术语

12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet

每日一题之干草堆的移动

wirehark数据分析与取证A.pacapng

1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】

Basic concept and implementation of overcoming hash
随机推荐
机器学习术语
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
Database SQL language 02 connection query
Telephone network problems
Delete duplicate elements in the ordered linked list -ii
Asynchronous, email and scheduled tasks
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
MySQL
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
Key wizard play strange learning - front desk and Intranet send background verification code
The meaning of wildcard, patsubst and notdir in makefile
数学知识:能被整除的数—容斥原理
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
异步、邮件、定时三大任务
按键精灵打怪学习-回城买药加血
Top ten regular spot trading platforms 2022