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. CSS3详解:transform、transition

    CSS3 transform是什么? transform的含义是:改变,使-变形:转换 CSS3 transform都有哪些常用属性? transform的属性包括:rotate() / skew() ...

  2. web前端学习路线和步骤

    H5+全栈工程师  (学习下列技术可以加QQ: 1416 7596 61)第一阶段:初级入门阶段基本功 1.HTML入门 Windows概述.浏览器概述.HTML简介.HTML标签详解.前端开发工具概 ...

  3. ACID 数据库正确执行四要素

    ACID:数据库事务正确执行所必须满足的四个基本要素的缩写: 原子性(atomicity,或叫不可分割性),一致性(consistency),隔离性(isolation,又称独立性),持久性(dura ...

  4. 基于gitHub+hexo搭建的个人博客

    文章导航 前期准备 安装hexo 修改hexo主题 自定义主题 部署本地文件到github查看 我的第一篇博客 前期准备 下载安装git命令行工具.node及npm环境 注册自己的GitHub账号 安 ...

  5. java工程师学习线路图

  6. VMware14.0.0 版本虚拟机安装Ubuntu16.04 LTS版本Linux系统(多图详细步骤)

    一.前期准备工作 1.成功安装完成VMware14软件: 2.去Ubuntu官网下载Ubuntu16.0.4 LTS 版本的镜像文件. 二.安装步骤 1.打开VMware软件,选择<创建虚拟机& ...

  7. C#获取存储过程的 Return返回值和Output输出参数值

    1.获取Return返回值  程序代码 //存储过程//Create PROCEDURE MYSQL//     @a int,//     @b int//AS//     return @a + ...

  8. [转载] 详述三种现代JVM语言--Groovy,Scala和Clojure

    转载自http://www.tuicool.com/articles/jYzuAv和http://www.importnew.com/1537.html 在我与Martin Fowler曾经合作呈现的 ...

  9. [转载] java垃圾回收机制

    转载自http://blog.csdn.net/randyjiawenjie/article/details/7551228 http://www.daniel-journey.com/archive ...

  10. JAVA基础面试(四)

    31.String s = new String("xyz");创建了几个StringObject?是否可以继承String类? 两个或一个都有可能,"xyz" ...