PKU 1067 取石子游戏

题目是中文,意思简单明了,不在赘述。

 

其实,就是一个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;

}

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值