1180. Stone Game

Time limit: 1.0 second

Memory limit: 64 MB
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

Problem Author: Dmitry Filimonenkov

Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002

解析:找规律。

考虑例如以下样例:

剩余石子的数量    first Nikifor

1                              win

2                              win

---- 依次选择1,2. 而且1 和 2是能够选择的。

3                              lose

---- 由于你选1或2的时候,另外一个人总能一次把剩下的取完。

4, 5                          win

---- 依次选择1,2,可以获胜。

6                              lose



7, 8                          win



.... 从上面的规律我们能够看出当 N mod 3 == 0 我们能确认first Nikifor一定能失败;否则的话。我们能选择的最小石子的数量 = N mod 3,此时first Nikifor获胜。

AC代码:

#include <bits/stdc++.h>
using namespace std; int main(){
int ans = 0;
char c;
while(scanf("%c", &c) && c != '\n') ans += c - '0'; //求个位数字之和以推断数字能否被3整除,数太大。直接存不下! if(ans % 3 == 0) puts("2");
else printf("%d\n%d", 1, ans % 3);
return 0;
}

.

URAL 1180. Stone Game (博弈 + 规律)的更多相关文章

  1. ural 1180 Stone Game

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

  2. timus 1180. Stone Game 解题报告

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

  3. Light OJ 1296 - Again Stone Game (博弈sg函数递推)

    F - Again Stone Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  4. Timus 1180. Stone Game 游戏题目

    Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns ...

  5. URAL 2070 Interesting Numbers (找规律)

    题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然 ...

  6. HDU 4764 Stone(博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 题目大意:Tang和Jiang玩石子游戏,给定n个石子,每次取[1,k]个石子,最先取完的人失败 ...

  7. poj1740 A New Stone Game[博弈]

    有若干堆石子,每一次需要从一堆石子中拿走一些,然后如果愿意的话,再从这堆石子中拿一些(揣度题意应该是不能拿出全部)分给其它任意不为空的堆.不能操作的人为负. 一直不会博弈啊..感觉完全就是个智商题,虽 ...

  8. HDU 4387 Stone Game (博弈)

    题目:传送门. 题意:长度为N的格子,Alice和Bob各占了最左边以及最右边K个格子,每回合每人可以选择一个棋子往对面最近的一个空格移动.最先不能移动的人获得胜利. 题解: k=1时 很容易看出,n ...

  9. hdu 3951(博弈规律)

    题意:给定围成一个圈的硬币n枚,然后每次可以取出连续的1-k枚,谁取完最后一枚谁就获胜. 分析:对于第二个人当第一个人取完后,他可以取成对称的形式,所以第二个人必胜. 代码: #include< ...

随机推荐

  1. [Swust OJ 842]--实验室和食堂(最短路,Dijkstra算法)

    题目链接:http://acm.swust.edu.cn/problem/842/ Time limit(ms): 1000 Memory limit(kb): 10000   Description ...

  2. OpenSSL命令---rand

    用途: 用来产生伪随机字节.随机数字产生器需要一个seed,先已经说过了,在没有/dev/srandom系统下的解决方法是自己做一个~/.rnd文件.如果该程序能让随机数字产生器很满意的被seeded ...

  3. Python 数据处理扩展包: pandas 模块的DataFrame介绍(创建和基本操作)

    DataFrame是Pandas中的一个表结构的数据结构,包括三部分信息,表头(列的名称),表的内容(二维矩阵),索引(每行一个唯一的标记). 一.DataFrame的创建 有多种方式可以创建Data ...

  4. Centos6.5搭建bugzilla

    一.安装httpd. mod_ssl. mysql-server . mysql .php-mysql . gcc . perl* . mod-perl-devel [root@localhost ~ ...

  5. VM添加e1000e驱动网卡

    关闭虚拟机 打开VMware 虚拟机配置 (.vmx),如

  6. JSpider是一个用Java实现的WebSpider

    JSpider是一个用Java实现的WebSpider,JSpider的执行格式如下: jspider [URL] [ConfigName] URL一定要加上协议名称,如:http://,否则会报错. ...

  7. windows下以指定用户访问SMB服务器进行读写

    需求:最近要开发某系统前端界面,但是该系统是部署在linux服务器上,前端是用php开发,实时调试运行需要linux下系统环境支持, 每次修改都需要手动传到服务器上,尤其是debug阶段,每修改一点就 ...

  8. BT基础知识简介

    1. 蓝牙概述   无线局域网的通信 适用范围:10米到100米(根据发射功率的class不同有所差别,典型的class2为10m,而class1为100m,class3为1m) 应用:   局域网络 ...

  9. Android中文API(129) —— AudioManager

    前言 本章内容是android.media.AudioManager,版本为Android 3.2 r1,翻译来自"文炜",欢迎访问他的博客:"http://www.cn ...

  10. HDU 2040:亲和数

    亲和数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...