B - Marbles Gym - 101908B (博弈论 SG原理)

B. Marbles
time limit per test0.5 seconds
memory limit per test1024 megabytes
inputstandard input
outputstandard output
Using marbles as a currency didn't go so well in Cubicônia. In an attempt to make it up to his friends after stealing their marbles, the Emperor decided to invite them to a game night in his palace.

Of course, the game uses marbles, since the Emperor needs to find some use for so many of them. N marbles are scattered in a board whose lines are numbered from 0 through L and the columns numbered from 0 through C. Players alternate turns. In his turn, a player must choose one of the marbles and move it. The first player to move a marble to position (0,0) is the winner. The movements are limited so the game could be more interesting; otherwise, the first player could just move a marble to position (0,0) and win. A movement consists in choosing an integer u greater than 0 and a ball, whose location is denoted by (l,c), and move it to one of the following positions, as long as it is inside the board:

(l−u,c) or;
(l,c−u) or;
(l−u,c−u).
Note that more than one marble can occupy the same position on the board.

As the Emperor doesn't like to lose, you should help him determine which games he should attend. Also, as expected, the Emperor always take the first turn when playing. Assuming both players act optimally, you are given the initial distribution of the marbles, and should find if it is possible for the Emperor to win if he chooses to play.

Input
The first line contains an integer N (1≤N≤1000). Each of the following N rows contains two integers li and ci indicating on which row and column the i-th marble is in (1≤li,ci≤100).

Output
Your program should print a single line containing the character Y if it is possible for the Emperor to win the game or N otherwise.

Examples
inputCopy
2
1 3
2 3
outputCopy
Y
inputCopy
1
1 2
outputCopy
N
View Problem

思路:

和普通的 sg思路很像,不过这个是第一个到达就win,难么 0,y || X,0|| A,A 这3个条件特判,直接就可以赢

所以 在sg转移(连边的时候)不能连接这3个点,因为你转移过去,就白给了,别人直接赢了

#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define M 100005

template <class G> void read(G &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9'){f|=ch=='-';ch==getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return ;
}

int n,m;
int sg[105][105],flag[M];
void inint(){
    
    sg[0][0]=0;
    for(ri i=1;i<=100;i++)
    {
        for(ri j=1;j<=100;j++)
        {
            
            if(i==j) continue;
        
            for(ri k=0;k<=200;k++)
            {
                flag[k]=0;
            }
            for(ri k=1;i-k>=1;k++)
            {
                if(i-k==j) continue;
                flag[sg[i-k][j]]=1;
            }
            for(ri k=1;j-k>=1;k++)
            {
                if(i==j-k) continue;
                flag[sg[i][j-k]]=1;
            }
            for(ri k=1;j-k>=1&&i-k>=1;k++)
            {
                flag[sg[i-k][j-k]]=1;
            }
            for(ri k=0;;k++)
            {
                if(!flag[k])
                {
                    sg[i][j]=k;
                    break;
                }
            }
        }
    }
    
}
int main(){

    inint();
    read(n);
    int ans=0;bool mm=0;
    for(ri i=1;i<=n;i++)
    {
        int a,b;
        read(a);read(b);
        if(a==0||b==0||a==b) mm=1;
        ans^=sg[a][b];
    }

    if(mm==1) printf("Y");
    else if(ans==0) printf("N");
    else printf("Y");
    return 0;
}
View Code

 

posted @ 2022-04-12 21:12  VxiaohuanV  阅读(34)  评论(0编辑  收藏  举报