`
bcyy
  • 浏览: 1951739 次
文章分类
社区版块
存档分类
最新评论

Timus 1180. Stone Game 游戏题目

 
阅读更多

Two Nikifors play a funny game. There is a heap ofNstones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition that this number is a nonnegative integer power of 2 (e.g. 1, 2, 4, 8 etc.). Nikifor who takes the last stone wins. You are to write a program that determines winner assuming each Nikifor does its best.

Input

An input contains the only positive integer numberN(conditionN≤ 10250holds).

Output

The first line should contain 1 in the case the first Nikifor wins and 2 in case the second one does. If the first Nikifor wins the second line should contain the minimal number of stones he should take at the first move in order to guarantee his victory.

Sample

input output
8
1
2

这也是个有趣的问题,也很经典的游戏题目的变形了。

不过这道题扩展了成为无限大的数了。

类似的游戏有:没人可以拿掉桌面上的棋子,每次不能超过5个,最后没棋子可以拿的算输


解决这样的题目只能是寻找规律了,不能真的模拟区玩了,否则必定超时。

这道题目的规律就是:

1 如果给出的stone是3的倍数,那么先取者必输

2 如果给出的不是3的倍数,那么先取者就凑成3的倍数就必赢,因为凑3的倍数很容易,去掉1个或者2个必定可以凑出来了

所以最后问题就成了mod3问题了。

我是怎么想出来的?

我是一个列子一个例子去观察,最后得出结论的,然后验证,AC,结论正确。

也挺花时间的。

#include <string>
#include <iostream>
using namespace std;

int StoneGameMod3(string &s)
{
	int carry = 0;
	for (int i = 0; i < s.size(); i++)
	{
		int a = carry * 10 + s[i] - '0';
		carry = a % 3;
	}
	return carry;
}

void StoneGame1180()
{
	string s;
	cin>>s;
	int mod3 = StoneGameMod3(s);
	if (0 == mod3) cout<<2;
	else cout<<1<<endl<<mod3;
}

int main()
{
	StoneGame1180();
	return 0;
}



分享到:
评论

相关推荐

    Times New Roman.TTF.rar

    在提供的压缩包中,我们看到有四款不同样式的Times New Roman字体文件:TIMES.TTF(常规)、TIMESBD.TTF(粗体)、TIMESI.TTF(斜体)和TIMESBI.TTF(粗体斜体)。这些不同的变体满足了设计师在文本表达时对于强调、...

    Times New Roman.ttf

    "Times New Roman.ttf"是与SMARTFORMS相关的字体文件,它在创建这些表单时可能会被用到。 首先,让我们深入了解SAP ABAP。ABAP(Advanced Business Application Programming)是SAP系统中的编程语言,用于开发企业...

    KITTI数据集00序列times.txt文件

    苦苦寻找的times文件,用于KITTI数据集SLAM测试 苦苦寻找的times文件,用于KITTI数据集SLAM测试 苦苦寻找的times文件,用于KITTI数据集SLAM测试

    Android Times Square.zip

    Android Times Square介绍: 效果不错的日历UI模块。可以设置成只能选择单个日期,或者可以选择多个不连续的日期,或者可以通过点击两个日期来选择之间连续的日期。并且可以将日历放到弹出的对话框中。   测试...

    KITTI数据集times序列的文本文档

    在SLAM应用中,`times.txt`文件可能包含了每个传感器数据帧的时间戳,这有助于精确地同步来自不同传感器的数据流。例如,它可能包含了每帧图像和LiDAR扫描的捕获时间。这些时间戳可以用于确保在进行特征匹配或运动...

    27Modern_Times_ExtraPack.rar

    27Modern_Times_ExtraPack.rar 27Modern_Times_ExtraPack.rar

    论文题目格式行距的具体要求.docx

    6. 三级节题目 设置:使用汉字小 4 号宋体、数字、外笔墨 母用 Times New Roman 小 4 号、20 磅行距、段前后 6 磅、居左,序号与题目 空 1 个汉字间隔。 7. 小题目 设置:使用小 4 号宋体、数字、外笔墨 母用 Times...

    ( Times New Roman.rar

    2. TIMES.TTF - 这是 Times New Roman 的常规(Regular)样式,也是基本的字体文件。 3. TIMESI.TTF - 这表示 Times New Roman 的斜体(Italic)版本。 4. TIMESBI.TTF - 这是 Times New Roman 的粗斜体(Bold ...

    Times

    "times.TTF"则是一个TrueType字体文件,包含了Times New Roman的所有字符和相关的排版信息,用户可以将其安装到计算机上,以便在各种应用程序中使用这种字体。 在IT实践中,了解和使用不同的字体对于设计师和开发...

    Times New Roman .fon

    Times New Roman .fon

    河南省鹤壁市鹤山区实验中学2020学年八年级英语上学期期中试题(B卷,无答案) 北师大版.doc

    - 题目5询问每周读英语的次数,"times"表示次数,所以选B. times。 - 题目6涉及动词enjoy的用法,后接动名词,即B. living。 - 题目7中,"on weekends"是固定搭配,表示在周末,因此选A. On。 - 题目8询问谁更...

    PyPI 官网下载 | mo-times-2.27.18331.tar.gz

    标题中的"PyPI 官网下载 | mo-times-2.27.18331.tar.gz"表明这是一个从Python Package Index(PyPI)官方源下载的软件包,名为"mo-times",版本号为2.27.18331,其格式是tar.gz。PyPI是Python开发者发布和获取开源库...

    Python库 | mo-times-5.53.21241.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:mo-times-5.53.21241.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    C_Times.工作室教您如何制作炫舞反11-20制作(第一节课)

    1. "C_Times.":这可能是一个专门从事游戏脚本开发或教程制作的工作室名称,他们提供了这个教学资源。 2. "炫舞反11-20上亿脚本":这可能是指工作室开发的脚本能够应对“炫舞”的高难度模式,而且可能有相当大的用户...

    cmd脚本-bat批处理-settimes.zip

    cmd脚本-bat批处理-settimes.zip

    ttf-mscorefonts-installer.zip

    在Linux系统中,为了使matplotlib库能够正确地显示如Times New Roman这样的Microsoft Core Fonts,我们需要进行额外的配置。"ttf-mscorefonts-installer.zip"这个压缩包正是为了解决这个问题,它包含了安装这些字体...

Global site tag (gtag.js) - Google Analytics