1465. Pawn Game
Time limit: 1.0 second
Memory limit: 64 MB
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:
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:
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
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;
}
}