-->
当前位置:首页 > 题库

PROGRAMMING:Who is the winner

Luz5年前 (2021-05-10)题库384
First, we introduce the game of chinsh and NIM
**Bash game * *: there is only a pile of $$n $$items. Two people take turns to take items from it. It is stipulated that at least one item at a time and at most $$M $$items at a time. The winner is the one who takes all the items. Obviously, if $$n = m + 1 $$, the maximum number can be m at a time,
Therefore, no matter how many items the first taker takes, the second taker can take the remaining items at one time, and the latter wins. Therefore, we found the rule of how to win: if $$n = (M + 1) * r + S $, ($$R $$is any natural number, $$s ≤ M $$), then the first mover takes $$s $$items. If the second mover takes $$K (< = m) $, then the first mover takes $$m + 1-k $$, and the result is $$(M + 1) * (R-1) $, then the first mover will win. In a word, if we want to keep the multiple of (M + 1) $, we can win the final, otherwise we will lose.
**Nim game * *: let's suppose there are three piles of items, and prove that this can be extended to the general case. There are three piles of several items in each pile. Two people take turns to take any number of $$(> = 1) $$items from a pile. It is stipulated that at least one item should be taken at a time. No more than one item is allowed. The winner will be the one who takes all the items.
This kind of situation is the most interesting. It has a close relationship with binary system. We use (a, B, c) to express a certain situation. First of all (0, 0, 0) is obviously a strange situation. No matter who faces the strange situation, he is bound to fail. The second strange situation is (0, N, n). As long as you take as many items as your opponent, you will end up with (0, 0, 0). After careful analysis, (1, 2, 3) is also a strange situation. No matter how the opponent takes it, it can be changed into (0, N, n). To put it bluntly, it has something to do with the binary XOR operation of the computer. If all the numbers are XOR, the latter will win.
Now, I ask you to combine the above two game characteristics to solve the following game problem: Xiao Hong and Xiao Ming are playing a game of taking stones, but they like freshness, so they come up with new moves to take stones** Now there are n piles of stones, each pile of stones has $$a [i] $. Xiaoming and Xiaohong can only take at least one and no more than $$M $$from one pile of stones in each round, and they can only take one pile of stones in each round. There is no need to take more than one pile of stones at the same time! Xiaoming first, Xiaohong second, and they are both smart enough to ask you to calculate who will win in the end**
###Input format:
In the first line, enter two integers n, m to represent n heaps of stones. Each pile can only take M at most$$ 1 <= n <= 500,1 <= m <= 1000$$)
There are m numbers in the next line, and the i-th number represents the number of i-th heaps of stones (set as $$a [i] $)$$ 1 <= a[i] <= 1e5$$);
###Output format:
The output line indicates who wins:
Xiaoming outputs "Xiaoming" when he wins;
If Xiaohong wins, it will output "Xiaohong";
###Input sample 1:
```in
2 1
1 1
```
###Output sample 1:
```out
xiaohong
```
###Input sample 2:
```in
2 2
1 2
```
###Output sample 2:
```out
xiaoming
```






answer:If there is no answer, please comment