当前位置:网站首页>NIM boben problem
NIM boben problem
2022-07-19 03:44:00 【Xiao Lu wants to brush the questions】
List of articles
subject
Given an array of positive numbers arr
The first hand and the second hand can choose to take several values in one position at a time ,
The value should be greater than 0, But less than the rest there
Who gets empty first arr, Who wins . according to arr, Return who wins
The title mean

All the numbers >=0, No one can take every round 0
Who gets the last point first wins 
First hand and second hand , extremely clever , Everyone is fully prepared for everything and himself ,
And absolutely rational , Ask you , Give you an array status to return who will win
Conclusion
All the numbers XOR up , If XOR sum is not equal to zero, win first , If XOR and equals 0 The backhand wins 
The first big goal :
Let the backhand face all the arrays first 0 The state of .
I don't know how to achieve the big goal , Switch goals ,
An XOR sum in which all numbers are XOR , If I can do it first, I face the XOR of these numbers and it is not equal to zero .
But every time I get it, I let my backhand face the XOR and equals 0, Then the final victory is the first
We know that in the end 0 When XOR and is 0. So play like this , It always has a moment full 0 When , And I can't meet , Will only let the backhand encounter , So my big goal of winning is turned into a seemingly more difficult goal by us .
Example

Write binary , Array 7,5,3 Global XOR and 001
First in 1 Here take one , become 6, Later 5,3 XOR sum 6 Together, XOR and are 0
When the back hand takes it again , No matter which number he takes in which position, he will definitely let XOR and from 0 Become not zero ,
Because he will inevitably change the number of one in a certain position , Changing its XOR and is not 0, Then continue to XOR and change it first 0, The first step is to win .
But what is the premise of doing this ? At the beginning, the XOR and must be non-zero in order to do so , If you face one first, it is XOR and equal 0 The state of , The backhand wins
Code
public static void printWinner(int[] arr) {
int eor = 0;
for (int num : arr) {
eor ^= num;
}
if (eor == 0) {
System.out.println(" The backhand wins ");
} else {
System.out.println(" Win first ");
}
}
边栏推荐
- Deep learning experiment notes
- Method of realizing horizontal and vertical centering of unknown width and height elements
- MySQL addition, deletion, query and modification (basic)
- [C语言勘误]数组长度的函数内获取方式错误
- options has an unknown property ‘before‘
- 通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动
- Sublime basic operation
- Boston house price analysis assignment summary
- 基于Pandoc与VSCode的 LaTeX环境配置
- GoogLeNet
猜你喜欢

Paper reading: u-net++: redesigning skip connections to exploit multiscale features in image segmentation

基于Matlab的男女声音信号分析与处理

374. Guess the size of numbers (must be able to get started)

Leetcode: subsequence problem in dynamic programming

About 1000base-t1 1000Base-TX and 100base-t1

S32k148evb about eNet loopback experiment

神器网站目录,全都是刚需好用的网站

Thinkphp5.0模型操作使用page进行分页

Machine learning library scikit learn (linear model, ridge regression, insert a column of data, extract the required column, vector machine (SVM), clustering)

Chengxin University envi_ IDL first week experiment test: simple operation of array + detailed analysis
随机推荐
渗透测试-02漏洞扫描
Cmake common commands
论文阅读:U-Net++: Redesigning Skip Connections to Exploit Multiscale Features in Image Segmentation
Machine learning library scikit learn (linear model, ridge regression, insert a column of data, extract the required column, vector machine (SVM), clustering)
374. 猜数字大小(入门 必会)
Introduction of modules (block, module)
SparkCore核心设计:RDD,220716,
谷歌 Chrome 浏览器安装 PWA 应用将显示更多描述信息
洛谷每日三题之第五天
Sublime basic operation
2022电工杯:5G 网络环境下应急物资配送问题(优化)
QT OpenGL moves 3D objects with mouse and keyboard (set camera)
Unity solves the problem of Z-fighting caused by overlapping objects with the same material
Chengxin University envi_ The second week of IDL experiment content: extract aod+ in all MODIS aerosol products for detailed analysis
IEEE754 standard floating point format
Simple usage and interface introduction of labelme
oracle 查询非自增长分区的最大分区
Underline shortcut
一文搞懂│什么是跨域?如何解决跨域?
Paper reading: u-net++: redesigning skip connections to exploit multiscale features in image segmentation