当前位置:网站首页>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;
}
边栏推荐
- MySQL
- Do not log in or log in to solve the problem that the Oracle database account is locked.
- Asynchronous, email and scheduled tasks
- 【面试题】1369- 什么时候不能使用箭头函数?
- 一位苦逼程序员的找工作经历
- Create your first Kivy program Hello word (tutorial includes source code)
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 【无标题】
- The difference between tail -f, tail -f and tail
- What are the trading forms of spot gold and what are the profitable advantages?
猜你喜欢
攻克哈希的基本概念与实现
Meituan dynamic thread pool practice ideas, open source
MySQL
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
基本远程连接工具Xshell
Androd Gradle 对其使用模块依赖的替换
How wide does the dual inline for bread board need?
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
随机推荐
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
tp6快速安装使用MongoDB实现增删改查
【无标题】
按键精灵打怪学习-前台和内网发送后台验证码
【面试题】1369- 什么时候不能使用箭头函数?
Arduino dy-sv17f automatic voice broadcast
MySQL foundation 05 DML language
按键精灵打怪学习-多线程后台坐标识别
产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
MySQL
Androd gradle's substitution of its use module dependency
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
Every k nodes in the linked list are flipped
[Androd] Gradle 使用技巧之模块依赖替换
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
Work experience of a hard pressed programmer
异步、邮件、定时三大任务
C#应用程序界面开发基础——窗体控制(3)——文件类控件
JS inheritance and prototype chain
Kivy教程大全之如何在 Kivy 中创建下拉列表