当前位置:网站首页>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;
}
边栏推荐
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- The meaning of wildcard, patsubst and notdir in makefile
- Detailed explanation of Q-learning examples of reinforcement learning
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
- [C language] detailed explanation of pointer and array written test questions
- MySQL basic usage 02
- Tp6 fast installation uses mongodb to add, delete, modify and check
- SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
- Machine learning terminology
- Thinkphp+redis realizes simple lottery
猜你喜欢
![leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]](/img/2c/8ec3926243fac8db9ed45d8053f3af.png)
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]

Using tensorboard to visualize the model, data and training process

dotConnect for PostgreSQL数据提供程序

MySQL

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

Asynchronous, email and scheduled tasks
![[Arduino experiment 17 L298N motor drive module]](/img/e2/4511eaa942e4a64c8ca2ee70162785.jpg)
[Arduino experiment 17 L298N motor drive module]

Basic remote connection tool xshell

MySQL basic usage 02

Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
随机推荐
The difference between tail -f, tail -f and tail
[principles of multithreading and high concurrency: 2. Solutions to cache consistency]
MySQL foundation 04 MySQL architecture
Test shift right: Elk practice of online quality monitoring
Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
Embrace the safety concept of platform delivery
异步、郵件、定時三大任務
[self management] time, energy and habit management
The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
一位苦逼程序员的找工作经历
Expérience de recherche d'emploi d'un programmeur difficile
MySQL - database query - basic query
Basic concept and implementation of overcoming hash
Merge K sorted linked lists
C#应用程序界面开发基础——窗体控制(1)——Form窗体
MySQL基础用法02
C#应用程序界面开发基础——窗体控制(3)——文件类控件
MySQL basic usage 02
力扣 204. 计数质数
Matlab finds the position of a row or column in the matrix