Ural 1465. Pawn Game nim博弈

1465. Pawn Game

Time limit: 1.0 second
Memory limit: 64 MB
In their free time, Santa Claus Petrovich and Santa Claus Egorych play the following game. Pawns are arranged on a board 3×3 in the following way:
Problem illustration
Pawns move and attack according to the standard chess rules, and there is one additional rule: it is obligatory to attack. The one who cannot make a move loses. White moves first. For the last 100 years, Petrovich have been playing white and he always won. Once Egorych became tired of this and brought a board 3×5. But he again was losing constantly playing black. "What's the matter", he thought and decided to buy a board 3× N:
Problem illustration
And here Petrovich has to think which color to play in order to win. Help him to decide.

Input

The integer  N (1 ≤  N ≤ 10 9).

Output

"White" if Petrovich should play white, and "Black" if he should play black. Egorych and Petrovich always make moves according to their optimal strategies.

Samples

input output
3
White
4
Black
5
White
Problem Author: Alexander Toropov
Problem Source: Ural SU Contest. Petrozavodsk Winter Session, January 2006
//nim博弈
#include <iostream>
using namespace std;
int sg[100000];
int a[10000];
int b[1000]= {1,0,0,0,0,0,1,0,0,0,1};
string m[2]= {"White","Black"};
int c[10000];
int main()
{
    sg[1]=1;
    sg[2]=1;
    int cnt=0;
    for(int i=3; i<=5000; i++)
    {
        a[sg[i-2]]=i;
        for(int j=0; j<=i-3; j++)
            a[(sg[j]^sg[i-j-3])]=i;
        for(int j=0; j<=i; j++)
            if(a[j]!=i)
            {
                sg[i]=j;
                break;
            }
        if(i>82)
        {
            c[cnt++]=sg[i];
        }
    }
    int n;
    cin>>n;
    if(n<=82)
    {
        if(sg[n])
            cout<<"White"<<endl;
        else
            cout<<"Black"<<endl;
    }
    else
    {
        n-=83;
        if(c[n%34])
            cout<<"White"<<endl;
        else
            cout<<"Black"<<endl;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值