Two Nikifors play a funny game. There is a heap of N stones 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 number N (condition N ≤ 10250 holds).

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的倍数非常easy,去掉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;
}

Timus 1180. Stone Game 游戏题目的更多相关文章

  1. timus 1180. Stone Game 解题报告

    1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...

  2. URAL 1180. Stone Game (博弈 + 规律)

    1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is ...

  3. ural 1180 Stone Game

    http://acm.timus.ru/problem.aspx?space=1&num=1180 #include <cstdio> #include <cstring&g ...

  4. Python-小游戏题目

    猜年龄游戏 n = 0 rayn_age = 19 a = {0:'666',1:'777',2:'888'} while n <3: age = input('请输入你的年龄:') age = ...

  5. 51nod 1180 方格射击游戏

    M*N的方格矩阵,一个人在左下角格子的中心,除他所站位置外,其他格子的中心都有一个敌人,他一次可发射一枚子弹干掉一条直线上的所有敌人,问至少要发射多少子弹才能干掉所有敌人. Input 输入2个数m, ...

  6. 博弈论题目总结(二)——SG组合游戏及变形

    SG函数 为了更一般化博弈问题,我们引入SG函数 SG函数有如下性质: 1.如果某个状态SG函数值为0,则它后继的每个状态SG函数值都不为0 2.如果某个状态SG函数值不为0,则它至少存在一个后继的状 ...

  7. NOIP2011 Mayan游戏

    3 Mayan游戏 题目描述 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个 7 行5 列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上 ...

  8. 洛谷P1118 数字三角形游戏

    洛谷1118 数字三角形游戏 题目描述 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少1,直 ...

  9. [Usaco2007 Open]Fliptile 翻格子游戏

    [Usaco2007 Open]Fliptile 翻格子游戏 题目 Farmer John knows that an intellectually satisfied cow is a happy ...

随机推荐

  1. AngularJS学习篇(二)

    AngularJS 指令 AngularJS 通过被称为 指令 的新属性来扩展 HTML. AngularJS 通过内置的指令来为应用添加功能. AngularJS 允许你自定义指令. Angular ...

  2. js 函数声明和函数表达式

    在ECMAScript中,创建函数的最常用的两个方法是函数表达式和函数声明,因为ECMA规范只明确了一点:函数声明必须带有标示符(Identifier)(就是大家常说的函数名称),而函数表达式则可以省 ...

  3. javascript中自定义事件

    自定义事件:用户可以指定事件类型,这个类型实际上就是一个字符串,然后为这个类型的事件指定事件处理函数,可以注册多个事件处理函数(用数组管理),调用时,从多个事件处理函数中找到再调用. function ...

  4. DataFrame使用总结1(超实用)

    DataFrame使用总结1(超实用): 1. 合并两个表 frame = [df1, df2] df = pd.concat(frame) res = pd.merge(df, df1, on=[' ...

  5. Luogu P2183 巧克力

    题目描述 佳佳邀请了M个同学到家里玩.为了招待客人,她需要将巧克力分给她的好朋友们.她有N(1<=N<=5000)块巧克力,但是大小各不一样,第i块巧克力大小为为1*Xi(1<=i& ...

  6. 分页查询时,使用cookie保存上次的查询条件。jQuery实现方法以及中间遇到的坑

    今天做分页查询时需要在跳转页面时保存上次查询的条件,如下: 实现的大致思路就是用cookie本地保存. 其中需要用到jQuery.Cookie插件. 使用方法很简单: 存数据:$.cookie(“ke ...

  7. hadoop启动name失败

    namenode失败十分的常见, 1.java.io.EOFException; Host Details : local host is: "hadoop1/192.168.41.134& ...

  8. ubuntu server小技巧(不定期更新)

    0.常用工具apt安装包名 # ssh服务器工具 apt-get install openssh-server # RabbitMQapt-get install rabbitmq-server # ...

  9. 《天书夜读:从汇编语言到windows内核编程》十 线程与事件

    1)驱动中使用到的线程是系统线程,在system进程中.创建线程API函数:PsCreateSystemThread:结束线程(线程内自行调用)API函数:PsTerminateSystemThrea ...

  10. 实战项目——mysql主从架构的实现

    一主一从 1.1 环境准备: centos系统服务器2台. 一台用户做Mysql主服务器, 一台用于做Mysql从服务器, 配置好yum源. 防火墙关闭. 各节点时钟服务同步. 各节点之间可以通过主机 ...