Ural 1180. Stone Game
来源:互联网 发布:大城市 小城市 知乎 编辑:程序博客网 时间:2024/06/01 11:28
1180. Stone Game
Time limit: 1.0 second
Memory limit: 64 MB
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
8
12
Problem Author: Dmitry Filimonenkov
Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
/** * *当n为三的倍数时,2一定会赢,否则当1第一次取n%3时一定会赢。 *证明:对于n=0,n=1,n=2时,命题显然成立。 *假设当对于任意的i(0<=i<=n-1)有命题成立 *当n不是三的倍数时,由于n%3一定为2的非负整数次幂,所以当1第一次取n%3个石子时,2一定会赢。 *当n是三的倍数时,前面败状态m一定是3的倍数,而 n-m 一定含有质因数3,即n-m一定不是2的非负整数次幂,因此1会赢。 * */#include<iostream>#include<string>using namespace std;int main(){ int sum=0; string str; cin>>str; for(int i=0;i<str.length();i++) sum+=str[i]-'0'; if(sum%3) cout<<"1"<<endl<<sum%3<<endl; else cout<<"2"<<endl; return 0;}
- Ural 1180. Stone Game
- ural 1180. Stone Game (博弈)
- URAL 1180. Stone Game (博弈 + 规律)
- Ural 1180 Stone Game
- URAL 1180 Stone Game
- 1180. Stone Game
- Stone Game
- Stone Game
- ural 1005 stone pile
- ural 1005. Stone Pile
- ural 1005 Stone Pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- ural 1005 Stone Pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- ural 1005 Stone Pile
- 矩阵相乘
- Python线程使用指南
- Command模式
- 如何让你成为一个专业的程序员(一)
- 2013腾讯编程马拉松初赛第〇场(3月20日)小明系列故事——买年货
- Ural 1180. Stone Game
- 写在《逆袭大学——传给IT学子正能量》修改稿提交之时
- Block详解
- php curl抓取远程页面内容的代码分享
- sgu Theodore Roosevelt【判断点是否在凸多边形内模板】
- MyEclipse 8.5 与MyEclipse 6.5代码自动提示设置
- ACM CLUB第四周周赛题解_部分
- 黑马程序员---毕向东老师视频笔记(关于static)
- 深入PHP curl参数的详解