当前位置:网站首页>Mathematical knowledge: step Nim game game game theory
Mathematical knowledge: step Nim game game game theory
2022-07-03 01:27:00 【Fight! Sao Nian!】
subject :AcWing 892. steps -Nim game
Now? , There is one n Stairs of steps , There are several stones on each step , Among them the first i There are... On the steps ai A stone (i≥1).
Two players take turns , Each operation can take several stones from any step and put them into the next step ( You can't stop taking ).
You can't take the stones on the ground anymore , In the end, those who can't do it are considered failures .
Ask if both of them adopt the optimal strategy , Whether the first is sure to win .
Input format
The first line contains integers n.
The second line contains n It's an integer , Among them the first i An integer represents the th i Number of stones on steps ai.
Output format
If you start first, you will win , The output Yes.
otherwise , Output No.
Data range
1≤n≤105,
1≤ai≤109
sample input :
3
2 1 3
sample output :
Yes
Topic analysis :
This question is similar to the previous one
a1^a3^a5…^an!=0 If you start, you will win
The strategy of winning first :
If you take even steps , Then put it on the next step , Will keep the odd steps unchanged .
If you take odd steps , Then XOR is not 0, Then the operation makes its XOR become 0.
conversely , If XOR is 0, Then the backhand wins .
#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;
}
边栏推荐
- LDC Build Shared Library
- MySQL basic usage 02
- Correctly distinguish the similarities and differences among API, rest API, restful API and web service
- [system analyst's road] Chapter V double disk software engineering (development model development method)
- R language uses coin package to apply permutation tests to independence problems (permutation tests, whether response variables are independent of groups, are two numerical variables independent, and
- [flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
- Machine learning terminology
- Dotconnect for PostgreSQL data provider
- Is there a handling charge for spot gold investment
- Cut point of undirected graph
猜你喜欢

leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】

MySQL foundation 04 MySQL architecture

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

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

leetcode 6103 — 从树中删除边的最小分数

JS inheritance and prototype chain

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9

信息熵的基础

【面试题】1369- 什么时候不能使用箭头函数?

Basic concept and implementation of overcoming hash
随机推荐
Create your first Kivy program Hello word (tutorial includes source code)
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
MySQL
力扣 204. 计数质数
Daily topic: movement of haystack
MySQL --- 数据库查询 - 条件查询
MySQL basics 03 introduction to MySQL types
Arduino dy-sv17f automatic voice broadcast
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
强化学习 Q-learning 实例详解
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
The industrial scope of industrial Internet is large enough. The era of consumer Internet is only a limited existence in the Internet industry
关于Fibonacci数列
Mongodb common commands of mongodb series
按键精灵打怪学习-回城买药加血
【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
Embrace the safety concept of platform delivery
Kivy tutorial - example of using Matplotlib in Kivy app
What are the trading forms of spot gold and what are the profitable advantages?
【第29天】给定一个整数,请你求出它的因子数