当前位置:网站首页>Mathematical knowledge: Nim game game theory
Mathematical knowledge: Nim game game theory
2022-07-03 01:27:00 【Fight! Sao Nian!】
subject :AcWing 891. Nim game
Given n Rubble , Two players take turns , Each operation can take any number of stones from any pile of stones ( You can finish it , But you have to take ), 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 A digital , Among them the first i A number means the i The number of stones .
Output format
If you start first, you will win , The output Yes.
otherwise , Output No.
Data range
1≤n≤105,
1≤ Number of stones per pile ≤109
sample input :
2
2 3
sample output :
Yes
Topic analysis :
This is the topic of game theory ,
Winning state ——> After the operation, the game can be in the state of first hand and failure
This problem uses XOR ,
a1,a2,a3,…an Express n The number of stones
If a1^a2^a3,…^an = 0 If you start, you'll lose
If a1^a2^a3,…^an!=0 The first step is to win
If the XOR value is not 0, Then the XOR value must be 0
If the XOR value is 0, No matter how you take it, you won't let the XOR value be 0
because 0^0^0=0
So to sum up , Come to the conclusion
#include <iostream>
using namespace std;
const int N = 100010;
int main()
{
int n,res=0;
cin>>n;
while(n--)
{
int x;
cin>>x;
res ^= x;
}
if(res)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
边栏推荐
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
- [fh-gfsk] fh-gfsk signal analysis and blind demodulation research
- 数学知识:Nim游戏—博弈论
- 机器学习术语
- 按键精灵打怪学习-自动回城路线的判断
- 给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
- Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
- MySQL foundation 06 DDL
- Machine learning terminology
- Excel calculates the difference between time and date and converts it into minutes
猜你喜欢
MySQL foundation 04 MySQL architecture
【无标题】
Why can't the start method be called repeatedly? But the run method can?
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
Top ten regular spot trading platforms 2022
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
[untitled]
Arduino dy-sv17f automatic voice broadcast
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
wirehark数据分析与取证A.pacapng
随机推荐
一比特苦逼程序員的找工作經曆
如今少年已归来,人间烟火气最抚凡人心 复工了~
信息熵的基础
Top ten regular spot trading platforms 2022
JDBC courses
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
Key wizard play strange learning - multithreaded background coordinate recognition
Makefile中wildcard、patsubst、notdir的含义
【C语言】指针与数组笔试题详解
Assets, vulnerabilities, threats and events of the four elements of safe operation
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
C#应用程序界面开发基础——窗体控制(3)——文件类控件
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
力扣 204. 计数质数
MySQL - database query - condition query
不登陆或者登录解决oracle数据库账号被锁定。
The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
按键精灵打怪学习-自动寻路回打怪点
The difference between tail -f, tail -f and tail