当前位置:网站首页>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;
}
边栏推荐
- leetcode 6103 — 从树中删除边的最小分数
- 信息熵的基础
- R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
- Androd Gradle 对其使用模块依赖的替换
- leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
- Strongly connected components of digraph
- [FPGA tutorial case 5] ROM design and Implementation Based on vivado core
- 给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
- Expérience de recherche d'emploi d'un programmeur difficile
- Trois tâches principales: asynchrone, courrier et timing
猜你喜欢

【C语言】指针与数组笔试题详解

软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053

Excel removes the data after the decimal point and rounds the number

Leetcode 6103 - minimum fraction to delete an edge from the tree

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

基本远程连接工具Xshell

Telephone network problems

How wide does the dual inline for bread board need?

Arduino DY-SV17F自动语音播报

无向图的割点
随机推荐
Niu Ke swipes questions and clocks in
JDBC courses
Basic remote connection tool xshell
Asynchronous, email and scheduled tasks
MySQL基础用法02
Leetcode 6103 - minimum fraction to delete an edge from the tree
MySQL foundation 04 MySQL architecture
Excel removes the data after the decimal point and rounds the number
按键精灵打怪学习-自动寻路回打怪点
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
Using tensorboard to visualize the model, data and training process
Makefile中wildcard、patsubst、notdir的含义
What operations need attention in the spot gold investment market?
[C language] detailed explanation of pointer and array written test questions
The meaning of wildcard, patsubst and notdir in makefile
测试右移:线上质量监控 ELK 实战
dotConnect for PostgreSQL数据提供程序
看疫情之下服装企业如何顺势而为
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
基本远程连接工具Xshell