Gym - 101908B Marbles SG定理

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

Input

2
1 3
2 3

Output

Y

Input

1
1 2

Output

N

题解:一个100*100的棋盘,坐标范围是[0, 100]的,上面有n个棋子。Alice 和 Bob轮流操作,每次操作可以把一枚棋子向左或者向下或者向斜下方移动任意步,也就是(x,y) 有这三种移动(x-l, y), (x, y-l), (x-l, y-l)。第一个把棋子移动到(0, 0)点的人获胜。

题解:通过这个题学习了一下SG定理 点击查看

#include <bits/stdc++.h>
using namespace std;
const int N=110;
int sg[N][N],vis[N * 10];
int n;
void init()
{
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			memset(vis,0,sizeof(vis));
			if(!i||!j||i==j)
			{
				sg[i][j]=-1;
				continue;
			}
			for(int k=1;k<i;k++)
			{
				if(i-k!=j) vis[sg[i-k][j]]=1;
			}
			for(int k=1;k<j;k++)
			{
				if(j-k!=i) vis[sg[i][j-k]]=1;
			}
			for(int k=1;k<min(i,j);k++)
			{
				vis[sg[i-k][j-k]]=1;
			}
			for(int k=0;;k++)
			{
				if(!vis[k])
				{
					sg[i][j]=k;
					break;
				}
			}
		}
	}
}
int main()
{
	init();
	int x,y;
	scanf("%d",&n);
	int ans=0;
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		if(x==y) flag=1;
		else ans^=sg[x][y];
	}
	if(ans) flag=1;
	printf(flag?"Y\n":"N\n");
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值