URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模
来源:互联网 发布:网络用语哔哔什么意思 编辑:程序博客网 时间:2024/05/17 00:00
题意:两人依次从一堆石子中取2的幂次个数的石子,如1 2 4 8 16…,能取到最后一颗石子的获胜。输入n,若第一人获胜则输出1和他第一次至少取多少个石子,若第二人获胜输出2。(n很大,10的250次幂)
结论:n%3=0则第二人获胜,否则第一人获胜且第一次至少取n%3个
心得:博弈题没有思路的时候就先找规律,足够敏感:取模,2的幂次,斐波那契等等!纸上演算或者写个程序跑打表观察!
http://acm.timus.ru/problem.aspx?space=1&num=1180
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
8
12
char s[300]; intsum=0; scanf("%s",s); for(int i=0; i<strlen(s); i++) sum+=(s[i]-'0'); if(sum%3==0) printf("2\n"); elseif (sum%3==1) printf("1\n1\n"); elseprintf("1\n2\n"); return 0;
- URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模
- URAL 1180. Stone Game (博弈 + 规律)
- hdu 1729 Stone Game 【博弈-找规律】
- hdu2674-水题-大数取模-打表找规律
- Stone Game(取石子游戏的三类博弈)
- [POJ](1740)A New Stone Game --找规律博弈(博弈)
- Ural 1180 Stone Game
- URAL 1180 Stone Game
- ural 1180. Stone Game (博弈)
- hdu 2516 取石子游戏(博弈,找规律)
- 【博弈-找规律】HDOJ 取石子游戏 2516
- Calendar Game(找规律+博弈)
- 【博弈+找规律】HDU_4642_Fliping game
- 大数操作-加/减/乘/除/取模
- Parity check——打表找规律+大数取模
- nyoj 358 取石子(五)(Fibonacci博弈)(博弈——找规律)
- 大数取模运算
- 大数取模
- 如何正确学习并提高学习效率?
- 15.1 类的委托
- 剑指offer——数值的整数次方
- HDOJ 1576 A/B(数论整除)
- c 到 unix c 高级编程中计算文件大小的三种方法
- URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模
- Python中protobuf
- Java枚举类型(一)
- 第十六章 Lambda与Java8
- Spring4笔记----为什么要使用AOP
- 在centOS上安装Ubuntu字体
- 16.1 Lambda
- 一步一步解析java集合框架LinkedList源码(3)
- HDU 2191 多重背包问题