Light OJ 1315 - Game of Hyper Knights

传送门

1315 - Game of Hyper Knights

   PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

A Hyper Knight is like a chess knight except it has some special moves that a regular knight cannot do. Alice and Bob are playing this game (you may wonder why they always play these games!). As always, they both alternate turns,
play optimally and Alice starts first. For this game, there are 6 valid moves for a hyper knight, and they are shown in the following figure (circle shows the knight).

They are playing the game in an infinite chessboard where the upper left cell is (0, 0), the cell right to (0, 0) is (0, 1). There are some hyper knights in the board initially and in each turn a player selects a knight and gives
a valid knight move as given. And the player who cannot make a valid move loses. Multiple knights can go to the same cell, but exactly one knight 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 of the next n lines contains two integersx y (0
≤ x, y < 500)
 denoting the position of a knight.

Output

For each case, print the case number and the name of the winning player.

Sample Input

Output for Sample Input


2

1

1 0

2

2 5

3 5


Case 1: Bob

Case 2: Alice

题目大意:

有n个骑士(1<=n<=1000)在无限的棋盘中,给定n个骑士的坐标(xi,yi),(0<=xi,yi<500)。骑士每一步有六种走法(详见图片),最后不能移动骑士的算输,问先手胜还是后手胜。

解题思路:

这是一个SG函数的问题,因为 n 个骑士是相互独立的, 注意到骑士总是往左边走,所以在计算每一格的SG函数时可以按照row+col为定值依次计算。注意到骑士只有六种走法,所以对于每一格的SG函数值SG(x,y)不会超过6。

My Code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1e3+5;
int mat[6][2] = {{-2,1}, {1,-2},{-2,-1},{-1,-2},{-3,-1},{-1,-3}};
bool hash[MAXN][MAXN];
int sg[MAXN][MAXN];
int get_SG(int x, int y)
{
    bool check[105];
    if(hash[x][y])
        return sg[x][y];
    hash[x][y] = 1;
    memset(check, false, sizeof(check));
    for(int i=0; i<6; i++)
    {
        int xx = x + mat[i][0];
        int yy = y + mat[i][1];
        if(xx>=0 && yy>=0)
            check[get_SG(xx,yy)] = 1;
    }
    for(int i=0; i<100; i++)
        if(!check[i])
            return sg[x][y] = i;
}
int main()
{
    int T;
    cin>>T;
    for(int cas=1; cas<=T; cas++)
    {
        int m, x, y;
        int ans = 0;
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d%d",&x,&y);
            ans ^= get_SG(x,y);
        }
        if(!ans)
            printf("Case %d: Bob\n",cas);
        else
            printf("Case %d: Alice\n",cas);
    }
    return 0;
}
 
时间: 2024-12-09 19:01:07

Light OJ 1315 - Game of Hyper Knights的相关文章

LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description A Hyper Knight is like a chess knight except it has some special moves that a regular knight cannot do. Alice and Bob are p

light oj 1236 【大数分解】

给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,--em, 则结果为((1+2*e1)*(1+2*e2)--(1+2*em)+1)/2. //light oj 1236 大数分解素因子 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #i

[2016-04-21][light]OJ[1234][Harmonic Number]

时间:2016-04-21 22:18:26 星期四 题目编号:[2016-04-21][light]OJ[1234][Harmonic Number] 题目大意:求∑nk=11kn∈(1,108),精确到10?8求∑k=1n1kn∈(1,108),精确到10?8 分析: 想法是打表,然后输出,但是直接打表会爆内存 解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值 对应的整百就是n

Light OJ 1411 Rip Van Winkle`s Code 线段树成段更新

题目来源:Light OJ 1411 Rip Van Winkle`s Code 题意:3中操作 1种查询 求区间和 其中每次可以把一段区间从左到右加上1,2,3,...或者从右到左加上...3,2,1 或者把某个区间的数都置为v 思路:我是加了6个域 add是这段区间每个数都要加上add  add是这么来的 对与123456...这个等差数列 可能要分为2个区间 那么我就分成123和123 两个右边的等差数列每个数还应该加上3 所以右区间add加3 v是这个区间都要置为v 他的优先级最高 b是

Light OJ 1168 Wishing Snake 强连通缩点+哈密顿通路

题目来源:Light OJ 1168 Wishing Snake 题意:有点难看懂题意 看了一个小时再加别人的代码才懂意思 从0开始 输入的那些每一对u v 都要经过 就是从0到到达那些点 思路:首先缩点 每一个强连通分量里面的点都是可达的 缩点后的图是有向无环图 如果从0这个强连通分量可以出去到2个强连通分量 那么这两个强连通分量是不可能相互可达 所以可行的方案就是所有的强连通分量连成一线 一个一个串起来 除了第一个 出度是1入度是0和最后一个出度是0入度是1 其他都是入度等于出度是1 特判只

Jan&#39;s light oj 01--二分搜索篇

碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计数问题,利用二分直接枚举可能的结果,再检查是否符合题目要求. 4.区间求解,即利用两次二分分别查找有序序列左右上下限,再求差算出总个数. 题型知识补充: 1. 三分的一般写法: 1 double thfind(double left,double right) 2 { 3 double midmid

light oj 1422 - Halloween Costumes (区间dp)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Ha

Light OJ 1341 Aladdin and the Flying Carpet

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery. Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised hi

Light OJ 1114 Easily Readable 字典树

题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 只要满足每个单词的首尾字符一样 中间顺序可以变化 思路:每个单词除了首尾 中间的字符排序 然后插入字典树 记录每个单词的数量 输入一个句子 每个单词也排序之后查找 根据乘法原理 答案就是每个单词的数量之积 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm>