当前位置:网站首页>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;
}
边栏推荐
- MySQL foundation 05 DML language
- Asynchronous, email and scheduled tasks
- 无向图的割点
- MySQL - database query - basic query
- Leetcode 2097 - Legal rearrangement of pairs
- [self management] time, energy and habit management
- Esp32 simple speed message test of ros2 (limit frequency)
- Mongodb common commands of mongodb series
- 不登陆或者登录解决oracle数据库账号被锁定。
- Look at how clothing enterprises take advantage of the epidemic
猜你喜欢
How is the mask effect achieved in the LPL ban/pick selection stage?
Androd gradle's substitution of its use module dependency
How is the mask effect achieved in the LPL ban/pick selection stage?
MySQL - database query - basic query
Matlab Doppler effect produces vibration signal and processing
Embrace the safety concept of platform delivery
MySQL基础用法02
MySQL
leetcode:701. Insertion in binary search tree [BST insertion]
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
随机推荐
LDC Build Shared Library
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
Telephone network problems
异步、邮件、定时三大任务
Excel removes the data after the decimal point and rounds the number
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
MySQL foundation 05 DML language
Kivy教程大全之如何在 Kivy 中创建下拉列表
[self management] time, energy and habit management
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
leetcode:701. Insertion in binary search tree [BST insertion]
【无标题】
看疫情之下服装企业如何顺势而为
Compare version number
Basis of information entropy
按键精灵打怪学习-回城买药加血
Look at how clothing enterprises take advantage of the epidemic
dotConnect for PostgreSQL数据提供程序