Game of Hyper Knights ---LightOJ - 1315

There are two pits in this question:
①The moving direction of the chess piece, there is no way back, so the passing point does not need to be marked with vis

② this board only the upper bound and left circles, the topic just given point x, y coordinate range, and did not give the board a range find bug find vomit , so in accordance with pieces from (500, 500) to the top right away, right boundary should It’s 750, go from (500, 500) to the bottom left, the lower bound is the 750
array and it’s good to be larger.

Others are recursive writing of ordinary sg functions. The recursive writing of sg function needs to pay attention to one point

int getSG(int x,int y){
    
    
	if(sg[x][y]!=-1) return sg[x][y];
	bool vis[N]={
    
    false}; //这一行不能放在全局,因为每次memset都会重置值
	for(int i=0;i<6;++i){
    
    
		int xx=x+dir[i][0],yy=y+dir[i][1];
		if(xx>=0&&yy>=0){
    
    
			vis[getSG(xx,yy)]=1;
		}
	}
	for(int i=0;;++i){
    
    
		if(!vis[i]){
    
    
			return sg[x][y]=i;
		}
	}
}

The rest can be determined according to the moving direction of the chess piece. Every time you move in the direction of the chess piece, it will stop when it hits the left and upper bounds.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+10;
int sg[N][N];
int dir[][2]={
    
    1,-2,-1,-3,-1,-2,-2,-1,-3,-1,-2,1};
int getSG(int x,int y){
    
    
	if(sg[x][y]!=-1) return sg[x][y];
	bool vis[N]={
    
    false};
	for(int i=0;i<6;++i){
    
    
		int xx=x+dir[i][0],yy=y+dir[i][1];
		if(xx>=0&&yy>=0){
    
    
			vis[getSG(xx,yy)]=1;
		}
	}
	for(int i=0;;++i){
    
    
		if(!vis[i]){
    
    
			return sg[x][y]=i;
		}
	}
}
int main(){
    
    
	memset(sg,-1,sizeof sg);
	int T,cas=0;scanf("%d",&T);
	while(T--){
    
    
		int n,ans=0;scanf("%d",&n);
		for(int i=1;i<=n;++i){
    
    
			int x,y;
			scanf("%d %d",&x,&y);
			ans^=getSG(x,y);
		}
		printf("Case %d: ",++cas);
		if(ans) puts("Alice");
		else puts("Bob");
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/bloom_er/article/details/107672507