博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[博弈]A Funny Game
阅读量:5324 次
发布时间:2019-06-14

本文共 1551 字,大约阅读时间需要 5 分钟。

A Funny Game

Description

Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) 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". 

Examples

Input

1230

Output

AliceAliceBob

正确解法:

有一圈硬币,两个人轮流拿一个或两个硬币,两个硬币必须是连续的,拿走的硬币会留下空位,中间有空位的硬币不算是连续的,那么到底是Alice赢了还是Bob。

当 n<=2 时,Alice当然可以全部拿走

当 n==3 时,无论Alice第一次拿了多少,Bob都能拿走,Bob必胜

当 n 时,无论Alice第一次拿了一个还是两个,Bob根据剩余的链长,决定在链的中间拿一个或者两个,把整条链分成完全相同的两半。之后Bob就可以模仿Alice的动作,到最后一定是Bob赢。

在这类游戏当中,作出对称的状态后再完全模仿对手的策略常常是有效的。

1 int n;2     while(scanf("%d",&n)!=EOF&&n)3     {4         if(n<=2)    puts("Alice");5         else    puts("Bob");6     }
View Code

 

转载于:https://www.cnblogs.com/Kaike/p/10675479.html

你可能感兴趣的文章
Tableau 学习资料
查看>>
中断和异常
查看>>
lucene 全文检索工具的介绍
查看>>
C# MD5-16位加密实例,32位加密实例
查看>>
无线点餐系统初步构思
查看>>
AJAX
查看>>
前端之CSS
查看>>
List注意点【修改】
查看>>
sqoop导入导出对mysql再带数据库test能跑通用户自己建立的数据库则不行
查看>>
拓扑排序的原理及其实现
查看>>
对StageWebView捕获位图时空白
查看>>
Provison Profile管理及存放路径
查看>>
shop--8.店铺列表展示--前端开发
查看>>
转:Can not issue data manipulation statements with executeQuery()错误解决
查看>>
详解C#委托,事件与回调函数(转)
查看>>
744. Find Smallest Letter Greater Than Target
查看>>
java实现二维码的生成.
查看>>
Android 发展思路
查看>>
Pythonic
查看>>
contentprovider的学习实例总结
查看>>