POJ-2484 A Funny Game (坑爹的博弈论)

今天寒假总结测试,呵呵,做出了史上最烂的一次比赛,只过了三道题,简直是无语死自己了,哎,还是自己不行啊,本题是卡了我最长时间的题,对,就是这坑爹的博弈论。题目在下:
Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 10 6) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can’t move, you lose.)

Figure 1

Note: For n > 3, we use c1, c2, …, cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)

Suppose that both Alice and Bob do their best in the game.
You are to write a program to determine who will finally win the game.
Input
There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 10 6). There are no blank lines between cases. A line with a single 0 terminates the input.
Output
For each test case, if Alice win the game,output “Alice”, otherwise output “Bob”.
Sample Input
1
2
3
0
Sample Output
Alice
Alice
Bob
题意:Alice和bob两个人玩拿硬币的游戏,把多个硬币围成一圈放在一起,每次只能拿一个或者是连着的两个(真tm会玩),最后一个拿完的那个人获得胜利。
吐槽:第一次做这题时本以为是道类似抢20那种游戏的题,结果两分钟搞完,一个大大的WA啊,仔细读完题之后才知道,原来只有是当硬币没有两个连接着的硬币是就没法拿两个。结果又被我理解为搜索题了,每次有几种状态,结果码了50多行直接就写不下去了。说实话,这题考察哪有数据结构和算法啊,真是想死的心都有了
正确思路:从样例中可以知道,是Alice先拿,当n > 3时,Alice拿过后环就会断裂成一条链,如果剩下的是奇数个,这时Bob直接从中间拿一个就可以把整条链分成完全相等的两部分了,如果是偶数就拿两个。然后Alice如果从任何一个链中拿一个,Bob就从另一个链中拿一个,Alice拿俩,Bob也拿俩。无论Alice怎么拿,Bob总是从另一条链中也怎么拿,所以到最后一定是Bob赢。(真tm好计谋啊)
代码直接就是判断n是否大于3就行了。哎无语啊。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值