当前位置:网站首页>数学知识:台阶-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;
}
边栏推荐
- 软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
- [FPGA tutorial case 5] ROM design and Implementation Based on vivado core
- Expérience de recherche d'emploi d'un programmeur difficile
- MySQL --- 数据库查询 - 基本查询
- On Fibonacci sequence
- [day 29] given an integer, please find its factor number
- excel表格计算时间日期的差值,并转化为分钟数
- Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
- 18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
- MySQL - database query - condition query
猜你喜欢

Excel calculates the difference between time and date and converts it into minutes

Matlab Doppler effect produces vibration signal and processing

MySQL - database query - basic query

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

异步、郵件、定時三大任務

leetcode:701. 二叉搜索树中的插入操作【bst的插入】

力扣 204. 计数质数

Excel removes the data after the decimal point and rounds the number
![[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

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
随机推荐
The meaning of wildcard, patsubst and notdir in makefile
基本远程连接工具Xshell
Create your first Kivy program Hello word (tutorial includes source code)
数学知识:能被整除的数—容斥原理
[system analyst's road] Chapter V double disk software engineering (development model development method)
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
tp6快速安装使用MongoDB实现增删改查
力扣 204. 计数质数
Button wizard play strange learning - automatic return to the city route judgment
[Arduino experiment 17 L298N motor drive module]
Basic remote connection tool xshell
LDC Build Shared Library
MySQL foundation 06 DDL
Work experience of a hard pressed programmer
Specified interval inversion in the linked list
MySQL - database query - condition query
d,ldc构建共享库
Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
Tp6 fast installation uses mongodb to add, delete, modify and check
数学知识:Nim游戏—博弈论