LightOJ 1315Game of Hyper Knights (SG函数)

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 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");

    }
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sigma函数是指一个数字的所有因子之和。给定一个数字n,需要求出有多少个数字的Sigma函数是偶数。\[2\] 为了解决这个问题,可以先筛选出n范围内的素数(范围在10^6即可),然后对n进行素因子分解。对于每个因子,如果它的Sigma函数中连乘的每一项都是偶数,那么整个Sigma函数就是偶数。具体实现中,可以判断每个因子的平方根是否为偶数,如果是偶数,则减去(平方根+1)/2。\[1\] 另外,还可以使用O(1)的做法来解决这个问题。根据观察,所有的完全平方数及其两倍的值都会导致Sigma函数为偶数。因此,可以直接计算n的平方根,然后减去(平方根+1)/2即可得到结果。\[3\] #### 引用[.reference_title] - *1* [Sigma Function](https://blog.csdn.net/PNAN222/article/details/50938232)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [【LightOJ1336】Sigma Function(数论)](https://blog.csdn.net/qq_30974369/article/details/79009498)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值