Article From:https://www.cnblogs.com/flightless/p/9064291.html

  The problem of unbiased game is a game of arbitrary situation that is equal to both sides of the game. That is to say, the next stage of the situation is determined, and it has nothing to do with who will go.

  Examples:

KThe master drew a row of N lattices on the paper. He wanted Xiao Ming and him to fill in the letters with them.1. when it is time for someone to fill in, L or O can only be filled in a space.2. who wins the word "LOL" first?3. if all the grids are full, they can not be made up.LOL, then the tie.Xiao Ming has been defeated several times, and he is ashamed. I hope you can use the computer to solve this puzzle for him.The input format of the problem is as follows:The first row, the digit n (n< 10), indicates that there are n initial situations below.Next, N line, each line is a string, indicating openThe beginning of the situation.For example, "* * * * *" indicates that there are 6 spaces. "L****" means a letter L on the left and 4 spaces on the right.It is required to output n numbers, indicating that for every situation, if Xiao Ming first fills up, when K master always uses the strongest method,The best result of Xiao Ming.1 means to win-1 is necessary to lose0 shows that it can be made to be flat
The code is as follows: a recursive procedure:
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int judge(string s)
{
    if(s.find("LOL")!=string::npos)//If before, LOL has been lost.
        return -1;
    if(s.find('*')==string::npos)//If there is no LOL and there is no space, it is a tie.
        return 0;
    int len=s.length();
    int ping=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='*')
        {
            s[i]='L';
            switch(judge(s))
            {
                case -1:return 1;//We're finished with LOL.
                case 0: ping=1; //We have finished the draw.
            }
            s[i]='O';
            switch(judge(s))
            {
                case -1: return 1;
                case 0:  ping=1;
            }
            s[i]='*';
        }
    }
    if(ping)
        return 0;
    return -1;
}
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    char s[30];
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        cout<<judge(s)<<endl;
    }
}

On the follow up of the SG function

Link of this Article: Unbiased game problems

Leave a Reply

Your email address will not be published. Required fields are marked *