当前位置:网站首页>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;
}
边栏推荐
- Matlab finds the position of a row or column in the matrix
- 每日一题之干草堆的移动
- Canvas drawing -- bingdd
- 对非ts/js文件模块进行类型扩充
- On Fibonacci sequence
- 按键精灵打怪学习-自动寻路回打怪点
- Database SQL language 01 where condition
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
- MySQL foundation 06 DDL
- Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
猜你喜欢
随机推荐
[shutter] animation animation (shutter animation type | the core class of shutter animation)
Androd Gradle 对其使用模块依赖的替换
Meituan dynamic thread pool practice ideas, open source
The meaning of wildcard, patsubst and notdir in makefile
一位苦逼程序员的找工作经历
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
MySQL --- 数据库查询 - 条件查询
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
Esp32 simple speed message test of ros2 (limit frequency)
Mongodb common commands of mongodb series
Delete duplicate elements in the ordered linked list -ii
异步、郵件、定時三大任務
强化学习 Q-learning 实例详解
Machine learning terminology
Is there a handling charge for spot gold investment
Is there anything in common between spot gold and spot silver
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
Kivy tutorial - example of using Matplotlib in Kivy app
有向图的强连通分量








