当前位置:网站首页>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 (shutter animation type | the core class of shutter animation)
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- 18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
- Using tensorboard to visualize the model, data and training process
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
- 【面试题】1369- 什么时候不能使用箭头函数?
- Swiftui component Encyclopedia: using scenekit and swiftui to build interactive 3D pie charts (tutorial with source code)
- Androd Gradle 对其使用模块依赖的替换
- 对非ts/js文件模块进行类型扩充
- What operations need attention in the spot gold investment market?
猜你喜欢

Androd Gradle 对其使用模块依赖的替换
![1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]](/img/bf/ab6838e34a3074130eac0a9992e77c.png)
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]

力扣 204. 计数质数

异步、邮件、定时三大任务

Assets, vulnerabilities, threats and events of the four elements of safe operation
![[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge](/img/ed/23331d939c9338760e426d368bfd5f.png)
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge

Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man

Androd gradle's substitution of its use module dependency

MySQL --- 数据库查询 - 条件查询

Trois tâches principales: asynchrone, courrier et timing
随机推荐
一位苦逼程序员的找工作经历
【FH-GFSK】FH-GFSK信号分析与盲解调研究
Specified interval inversion in the linked list
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
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
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
Androd gradle's substitution of its use module dependency
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
Kivy教程大全之如何在 Kivy 中创建下拉列表
按键精灵打怪学习-前台和内网发送后台验证码
[Arduino experiment 17 L298N motor drive module]
d,ldc構建共享庫
Draw love with go+ to express love to her beloved
【FPGA教程案例6】基于vivado核的双口RAM设计与实现
Every k nodes in the linked list are flipped
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
[shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
Top ten regular spot trading platforms 2022
[untitled]