The Game of 31

The game of 31 was a favorite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labeled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming each player plays the remainder of the game using a perfect stratefy.
For example, in the following game player B wins:

Player A plays 3
Player B plays 5
Player A plays 6
Player B plays 6
Player A plays 5
Player B plays 6

Input

The input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete the game using a perfect strategy for both players and to determine who wins.

Output

For each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game.

Sample Input

356656
35665
3566
111126666
552525

Sample Output

356656 B
35665 B
3566 A
111126666 A
552525 A

0

查看全部2条回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
The Game of 31
The game of 31 was a favorite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labeled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming each player plays the remainder of the game using a perfect stratefy.nFor example, in the following game player B wins:nnPlayer A plays 3nPlayer B plays 5nPlayer A plays 6nPlayer B plays 6nPlayer A plays 5nPlayer B plays 6nnnInputnnThe input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete the game using a perfect strategy for both players and to determine who wins.nnnOutputnnFor each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game.nnnSample Inputnn356656n35665n3566n111126666n552525nnnSample Outputnn356656 Bn35665 Bn3566 An111126666 An552525 An
生命游戏(c语言)
Conway——the game of life,特别发行的精装版,以此来纪念一年来学习编程的蛋疼时光!
vi的行符,doxygen注释,缩进,代码高亮设置
1.对于代码缩进,代码高亮,一般只要是最新的版本就可以了, 如果是设置的话就是在 /usr/share/vim/.vimrc 只要在一般是 vi /usr/share/vim/.vimrc 在.vimrc文件里面添加结尾处添加 set nu “显示行符号 set autoindent ”缩进 set cindent " c代码高亮 就可以了 那么doxygen是需要在官方下载一个Do
android 最新31个游戏合集 game 31个_2.rar
android 最新31个游戏合集 game 31.rar 第二个包
android 最新31个游戏合集 game 31个_3.rar
第三个包,android 游戏 game G3 G2之前已经描述了
3D游戏引擎编程_part5of31
3D Game Engine Programming 3D游戏引擎编程 pdf 一共31个包,下齐后解压.
game game game game game
很好玩的小游戏,适合上班时间消遣!有空下了玩玩吧!
the game crashed的可能解决方案
打开游戏,或者一些类似游戏的软件时报错: 优先参考:https://tieba.baidu.com/p/5227459178?pv=1 如果按照上面的方案解决不了问题,你可以尝试切换显卡。 有一些国产辣鸡 软件不支持独立显卡,将该程序指定为使用集成显卡即可。 (没有外国月亮比较圆的意思,流入我们视线的外国软件,都是经过筛选的) ...
Game AI Pro 3 Collected Wisdom of Game AI Professionals 无水印pdf
Game AI Pro 3 Collected Wisdom of Game AI Professionals 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Game Engine Architecture(中英两版本)
注意:中文版只有第1章和第14章。 该书对游戏引擎包含渲染引擎、物理引擎、碰撞检测系统、音效、脚本引擎、电脑动画、人工智能、网络引擎以及场景管理进行详细深入的介绍。本资源是Game Engine Architecture(游戏引擎架构)设计的经典教材,在此为了方便大家学习,包含了中文与英文两个版本;给那些游戏引擎爱好者十足的学习提高自己的机会。
3D游戏引擎编程part25of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part31of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part1of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part21of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part4of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part28of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part18of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part23of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
Game Engine Architecture 3rd Edition
游戏引擎开发第三版高清版 New to the Third Edition This third edition offers the same comprehensive coverage of game engine architecture provided by previous editions, along with updated coverage of: computer and CPU hardware and memory caches, compiler optimizations, C++ language standardization, the IEEE-754 floating-point representation, 2D user interfaces, plus an entirely new chapter on hardware parallelism and concurrent programming.
3D游戏引擎编程part26of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part24of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
facebook instant game 发布指南-最佳实践
小游戏最佳实践构建小游戏时,要求使用 HTML5 语言。下面是关于开发小游戏的一系列最佳实践:加载时间与性能   初始加载时间不应超过 5 秒:小游戏必须能够“即时”加载,如果初始加载时间太长,玩家将趋向于流失。捆绑包的总大小最多可为 200 MB,但在初始加载期间,我们仅加载您的index.html明确要求的文件。因此,请确保在初始加载期间仅加载关键素材,用于开启首次会话,并延迟其他素材的加载,...
jump game 贪心算法
给定一个非负整数数组,假定你的初始位置为数组第一个下标。 数组中的每个元素代表你在那个位置能够跳跃的最大长度。 请确认你是否能够跳跃到数组的最后一个下标。 例如:A = [2,3,1,1,4]A=[2,3,1,1,4] 能够跳跃到最后一个下标,输出true; A = [3,2,1,0,4]A=[3,2,1,0,4] 不能跳跃到最后一个下标,输出false。 输入格式 第一行输入
A course in game theory
如果你受过严格数学思维训练,你“从入门到精通” 掌握博弈论只需要一本书:A Course in Game Theory ( by Martin Osborne and Ariel Rubinstein). 此书的深度,广度,视角,表述,例题等极优秀,也非常适合自学。另外,此书可免费下载,有中文译本,习题似乎也有答案。(关于数学思维能力的一个“小”测试:自己是不是能顺利读下以前未接触过的纯数学方向研究生级课本的前两章)
3D游戏引擎编程_part8of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压
3D游戏引擎编程part13of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part11of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part2of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part20of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part29of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part19of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part10of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part27of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part9of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
Game Mechanics Advanced Game Design
Game Mechanics Advanced Game Design
Game For Windows Live
用以解决某些游戏(如GTA4)缺少xlive.dll的问题,彻底解决此问题需要安装Game For Windows Live。
facebook instant game 发布指南-游戏表现
监控并改善游戏表现游戏上线后,持续监控关键指标非常重要。密切关注相关指标有助于您了解功能设计的质量、洞察受众数据,以及确定游戏更新是否能保持游戏正常运行。本文档将介绍一些最佳实践,助您了解如何利用Facebook 分析监控游戏的表现。筛选游戏数据自定义应用事件A/B 测试筛选游戏数据Once your game is live, you should follow closely your gam...
3D游戏引擎编程_part6of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part14of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part15of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
文章热词 设计制作学习 机器学习教程 Objective-C培训 交互设计视频教程 颜色模型
相关热词 mysql关联查询两次本表 native底部 react extjs glyph 图标 31岁java学习 31岁学习人工智能