题目是中文,意思简单明了,不在赘述。
其实,就是一个Wythoff Game。根据wiki上面的介绍就能求解。
Optimal Strategy
Any position in the game can be described by a pair of integers (n, m) with n ≤ m, describing the size of both piles in
the position. The strategy of the game revolves around cold positions and hot positions: in a cold position, the player
whose turn it is to move will lose with best play, while in a hot position, the player whose turn it is to move will win
with best play. The optimal strategy from a hot position is to move to any reachable cold position.
The classification of positions into hot and cold can be carried out recursively with the following three rules:
1. (0,0) is a cold position.
2. Any position from which a cold position can be reached in a single move is a hot position.
3. If every move leads to a hot position, then a position is cold.
Formula for Cold Position
nk = [ki]
mk = [ki2] = nk + k
其中,[]是下取整函数floor,i是黄金分割数= (sqrt(5.0) + 1) / 2。
#include <iostream>
#include <math.h>
const double GOLDEN_RATIO = (sqrt((double)5) + 1) / 2;
int main()
{
__int64 a, b;
while(2 == scanf("%I64d %I64d", &a, &b))
{
if(a > b)
{
__int64 temp = a;
a = b;
b = temp;
}
__int64 diff = b - a;
if(a == (__int64)floor(diff * GOLDEN_RATIO))
{
printf("0/n");
}
else
{
printf("1/n");
}
}
return 0;
}