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. Problem F: 多少个最大值?

    Description 输入若干个int类型的整数,求它们的最大值及其个数. Input 输入 若干个int类型的整数,至文件尾为止. Output 输出只有一行:There are # maximu ...

  2. WebP 的前世今生

    除了视频,图片占据了 PC 和 App 的大部分流量,为运营方带来高额的成本支出,同时过多的图片加载会影响到网站与 App 的加载速度.因此在保证图片质量的前提下缩小图片的体积就成了迫在眉睫的事情. ...

  3. redhat7 Samba

    1.先安装Samba服务 yum install -y samba samba-client 2.配置文件 vi /etc/samba/smb.conf  --主配置文件 [global]  --全局 ...

  4. wordpress搬家到 linode 步骤简析

    1. 购买并安装系统 购买就不说了哈,英文不好的自己搜教程. 然后是安装系统 linode 系统安装: 购买完成后登录,进入找到购买的vps ,点击 Dashboard (控制面板) 进入后点击 面板 ...

  5. 基于python3.x,使用Tornado中的torndb模块操作数据库

    目前Tornado中的torndb模块是不支持python3.x,所以需要修改部分torndb源码即可正常使用 1.开发环境介绍 操作系统:win8(64位),python版本:python3.6(3 ...

  6. 如何优雅的设计React组件

    如何优雅的设计 React 组件 如今的 web 前端已被 React.Vue 和 Angular 三分天下,一统江山十几年的 jQuery 显然已经很难满足现在的开发模式.那么,为什么大家会觉得 j ...

  7. SQL SERVER 2012设置自动备份数据库

    为了防止数据丢失,这里给大家介绍SQL SERVER2012数据自动备份的方法: 一.打开SQL SERVER 2012,如图所示: 服务器类型:数据库引擎: 服务器名称:127.0.0.1(本地), ...

  8. Markdown简易语法说明

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  9. C#去掉字符串头尾指定字符

    private void button2_Click(object sender, EventArgs e)        {//去掉字符串头尾指定字符            string MyInf ...

  10. Python之re模块(结合具体业务)

    1.判断数据库名是否合法 import re dbname = "test_" result = re.match("[a-zA-Z_0-9]{1,}$",db ...