1315 - Game of Hyper Knights
PDF (English) Statistics Forum Time Limit: 1 second(s)Memory Limit: 32 MBA Hyper Knight is like a chess knight except it has somespecial moves that a regular knight cannot do. Alice and Bob are playing thisgame (you may wonder why they always play these games!). As always, they bothalternate turns, play optimally and Alice starts first. For this game, thereare 6 valid moves for a hyper knight, and they are shown in the followingfigure (circle shows the knight).
They are playing the game in an infinite chessboard wherethe upper left cell is (0, 0), the cell right to (0, 0) is (0, 1). There aresome hyper knights in the board initially and in each turn a player selects aknight and gives a valid knight move as given. And the player who cannot make avalid move loses. Multiple knights can go to the same cell, but exactly oneknight should be moved in each turn.
Now you are given the initial knight positions in the board,you have to find the winner of the game.
Input
Input starts with an integer T (≤ 200),denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤n ≤ 1000) where n denotes the number of hyper knights. Each ofthe next n lines contains two integers x y (0 ≤ x, y <500) denoting the position of a knight.
Output
For each case, print the case number and the name of thewinning player.
Sample Input
Output for Sample Input
2
1
1 0
2
2 5
3 5
Case 1: Bob
Case 2: Alice
题意:
有y组数据,每组数据有n个棋子放在棋盘上,有两个人A,B,两个人轮流移动棋子,A先,若轮到某个人,没有棋子可以移的话,就判定给人失败
移棋子的规则是如上图,只有上述的6中移法
解析:
说实话,这道题不太懂,看了题解,按他的代码写出来的,
虽然看了大牛的博客,但还是一知半解大牛博客,详解SG函数
这里用SG 我们就不需要去手推规律了(可能里面也没规律),就无脑的套sg的模板和结论就可以了,不过,这里有一点没有搞懂,就是sg函数的取值范围
这里说是因为只有6个方向,所以最大只能是6?????
还有这里用dfs版本的sg模板,而不用打表是因为vis[dfs(nx,ny)]=1,这一步,因为你无法保证当前的sg[nx][ny]是已经算过的,打表的版本,这一步是保证在之前的循环就已经算过的了,所以这里需要用dfs版本的
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3+10; int sg[MAXN][MAXN]; int nex[6][2]={-3,-1,-2,1,-2,-1,-1,-2,-1,-3,1,-2}; int dfs(int x,int y) { int vis[7]={0}; //? if(sg[x][y]!=-1) { return sg[x][y]; } for(int i=0;i<6;i++) { int nx=x+nex[i][0]; int ny=y+nex[i][1]; if(nx>=0&&ny>=0) vis[dfs(nx,ny)]=1; } for(int j=0;j<7;j++) { if(!vis[j]) return sg[x][y]=j; } } int main() { int t,n; scanf("%d",&t); memset(sg,-1,sizeof(sg)); for(int i=1;i<=t;i++) { scanf("%d",&n); int ans=0; for(int j=0;j<n;j++) { int x,y; scanf("%d%d",&x,&y); ans^=dfs(x,y); } printf("Case %d: ",i); if(ans) printf("Alice\n"); else printf("Bob\n"); } }