# hdu 1730 Northcott Game (二维sg函数)

Posted by 111qqz on Friday, July 22, 2016

## TOC

hdu 1730

1A蛤蛤蛤

``````/* ***********************************************
Author :111qqz
Created Time :2016年07月22日 星期五 21时01分19秒
File Name :code/hdu/1730.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=2E2+7;
bool vis[N*N];
int sg[N][N];
int n,m;

void sg_init(int m)
{
ms(sg,0);

for ( int i1 = 1 ; i1 <= m ; i1++)
for ( int i2 = 1 ; i2 <= m ; i2++)
{
if (i1==i2) continue ;  // 棋子不能在同一个位置？
ms(vis,false);

int x = i1;
int y = i2;

if ( x<y )
{
for ( int j = x+1 ; j <=y-1;  j++)
vis[sg[x][j]] = true;

for ( int j = 1 ; j <= x-1 ; j++)
vis[sg[j][y]] = true;
}
else
{
for ( int j = y + 1 ; j  <= x-1 ; j++)
vis[sg[j][y]] = true;

for ( int j =1 ; j <= y-1 ; j++)
vis[sg[x][j]] = true;
}

for ( int j1  = 1 ;  j1 <= m ; j1++ )
for ( int j2 = 1 ; j2 <= m ; j2++)
if (!vis[j1*m+j2])
{
//cout<<"acccc"<<endl;
sg[i1][i2] = j1*m+j2;
break;
}
}
}
int main()
{
#ifndef  ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif

sg_init(105);

//	for ( int i =  0 ;i <= 10 ; i++)
//	    for ( int j = 0  ; j <= 10 ; j++)
//		cout<<"i:"<<i<<" j:"<<j<<" "<<sg[i][j]<<endl;
while (~scanf("%d%d",&n,&m))
{
int sum = 0 ;
for ( int  i = 1 ; i <= n ; i++)
{
int x,y;
scanf("%d%d",&x,&y);
int tmp = sg[x][y]-11026;
sum^=tmp;
}
if (sum)
{
puts("I WIN!");
}
else
{
}
}

#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
``````

「真诚赞赏，手留余香」