当前位置:网站首页>数学知识:台阶-Nim游戏—博弈论
数学知识:台阶-Nim游戏—博弈论
2022-07-03 01:03: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;
}
边栏推荐
- matlab查找某一行或者某一列在矩阵中的位置
- leetcode 2097 — 合法重新排列数对
- 按鍵精靈打怪學習-多線程後臺坐標識別
- Delete duplicate elements in the ordered linked list -ii
- 力扣 204. 计数质数
- [自我管理]时间、精力与习惯管理
- Daily topic: movement of haystack
- On Fibonacci sequence
- Excel if formula determines whether the two columns are the same
- 1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
猜你喜欢
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
JDBC courses
Matlab Doppler effect produces vibration signal and processing
Basis of information entropy
Niu Ke swipes questions and clocks in
Machine learning terminology
一位苦逼程序员的找工作经历
ROS2之ESP32简单速度消息测试(极限频率)
Merge K sorted linked lists
Androd Gradle 对其使用模块依赖的替换
随机推荐
MySQL foundation 04 MySQL architecture
用Go+绘制爱心给心爱的她表白
【面试题】1369- 什么时候不能使用箭头函数?
【FH-GFSK】FH-GFSK信号分析与盲解调研究
Basic concept and implementation of overcoming hash
对非ts/js文件模块进行类型扩充
Is there a handling charge for spot gold investment
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
leetcode:701. Insertion in binary search tree [BST insertion]
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
Button wizard play strange learning - automatic return to the city route judgment
Key wizard hit strange learning - automatic path finding back to hit strange points
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
Work experience of a hard pressed programmer
MySQL - database query - basic query
leetcode 6103 — 从树中删除边的最小分数
Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
[day 29] given an integer, please find its factor number
Compare version number
Arduino dy-sv17f automatic voice broadcast