当前位置:网站首页>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;
}
边栏推荐
- Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
- [C language] detailed explanation of pointer and array written test questions
- 数学知识:能被整除的数—容斥原理
- Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
- Leetcode 6103 - minimum fraction to delete an edge from the tree
- [principles of multithreading and high concurrency: 2. Solutions to cache consistency]
- Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
- 给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
- d. LDC build shared library
- 1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
猜你喜欢
![leetcode:701. Insertion in binary search tree [BST insertion]](/img/bc/1dda73198488eb81b49be2c1dff6c2.png)
leetcode:701. Insertion in binary search tree [BST insertion]

Basis of information entropy

MySQL foundation 05 DML language

每日一题之干草堆的移动

Matlab Doppler effect produces vibration signal and processing

Database SQL language 01 where condition

leetcode 6103 — 从树中删除边的最小分数

Excel calculates the difference between time and date and converts it into minutes

Esp32 simple speed message test of ros2 (limit frequency)

MySQL basics 03 introduction to MySQL types
随机推荐
MySQL --- 数据库查询 - 条件查询
leetcode:701. Insertion in binary search tree [BST insertion]
Mongodb common commands of mongodb series
JS inheritance and prototype chain
MySQL foundation 07-dcl
[day 29] given an integer, please find its factor number
MySQL - database query - basic query
信息熵的基础
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge
Look at how clothing enterprises take advantage of the epidemic
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
攻克哈希的基本概念与实现
[self management] time, energy and habit management
Excel removes the data after the decimal point and rounds the number
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
[shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
Draw love with go+ to express love to her beloved
异步、郵件、定時三大任務
R language ggplot2 visual faceting, visual facet_wrap bar plot, using strip Text function customize the size of the strip of each facet title in the facet graph (cutimi
Machine learning terminology