Luo Gu P3150 pb games (1) introductory explanations Game Theory

Topic links: https://www.luogu.org/problem/P3150
This question is game theory introductory questions.
We win state and losing state to explain the problem.
First, the following picture demonstrates the first eight and the number of winning state losing state:

can be found:

  • When \ (m = 1,3,5,7 \) when the states are doomed to failure;
  • When \ (m = 2,4,6,8 \) all the time win state.

We wish to use mathematical induction to prove it:
For any larger than 8 \ (m \) , I assumed that it is known in front of \ (m-1 \) number of states has been determined, and the odd state is losing , are the even win state. then:

  • If \ (m \) is odd, then it anyway points are divided into a less than \ (m \) odd and smaller than \ (m \) is an even number, i.e. in any event will leave opponents a win points state (even), then \ (m \) to state I is doomed to failure;
  • If \ (m \) is an even number, it can be divided into two odd (left case two opponents losing states), may be divided into two even (left case two opponents win state), however, because I absolutely smart, so I'm sure will be divided into two odd, so in this case \ (m \) for me is to win state.

In summary, it can be concluded: all even states are win, all odd states are doomed to failure.

Codes are as follows:

#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
    cin >> n;
    while (n --) {
        cin >> m;
        puts( m % 2 ? "zs wins" : "pb wins");
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/codedecision/p/11788241.html
Recommended