Left Right (尼姆博弈)

原题目:

Two players, Alice and Bob are playing a strange game in a 1 x n board. The cells are numbered from 0 to n-1, where the left most cell is marked as cell 0. Each cell can contain at most one piece.

Fig 1: an example

There are two kinds of pieces, gray and white. Alice moves all gray pieces, and bob moves all white ones. The pieces alternate, that is, leftmost piece is gray, next is white, next to that is gray, then it's white again, and so on. There will always be equal number of black and gray pieces. Alice can only move pieces to the right. Bob can only move pieces to the left.

At each move, a player selects one piece and moves that piece, either to its left (Bob) or to its right (Alice), any number of cells (at least 1) but, it can neither jump over other pieces, nor it can move outside the board. The players alternate their turns.

For example, if Alice decides to move the left most gray piece, these two moves are available to her.

Fig 2: Moving the gray piece one cell to the right

Fig 3: Moving the gray piece two cells to the right

Alice moves first. The game ends, when someone is unable to make any move, and loses the game. You can assume that, both of them play optimally (that is, if it is possible to apply a strategy that will ensure someone's win, he/she will always use that strategy).

Now you are given a configuration of a board, you have to find the winner.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case starts with a line containing an integer k (1 ≤ k ≤ 100) denoting the number of gray pieces in the board. The next line contains 2k distinct integers (in ascending order) denoting the position of the pieces. The first integer denotes a gray piece, the second integer denotes a white piece, the next integer denotes a gray piece and so on. All the integers will lie in the range [0, 109]. Assume that n is sufficiently large to contain all the pieces. And at least one move is remaining.

Output

For each case, print the case number and 'Alice' or 'Bob' depending on the winner of the game.

Sample Input

2

2

0 3 7 9

2

1 3 7 9

Sample Output

Case 1: Alice

Case 2: Bob

中文概要:
给定n对点,每一对点中第一个点向右走,第二个点向左右,不能跨越...谁不能走谁输...问最后谁赢。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000007
#define inf 0x3f3f3f3f
#define N 100100
int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        int n;
        scanf("%d",&n);
        int a,b,ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&a,&b);
            ans=ans^(b-a-1);
        }
        if(ans)
            printf("Case %d: Alice\n",cas);
        else
            printf("Case %d: Bob\n",cas);
    }
    return 0;
}

把一对点的可以走的距离当成石子数量,就变为NIM博弈了..

不看解析想不出来。。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deebcjrb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值