URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模
2016-07-30 10:27
459 查看
题意:两人依次从一堆石子中取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
结论: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.
|
input | output |
---|---|
8 | 1 2 |
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 (博弈)
- POJ1740_A New Stone Game_推规律的博弈
- POJ 1740 A New Stone Game 博弈,规律
- POJ 1740 A New Stone Game(多堆博弈找规律)
- hdu 1729 Stone Game 【博弈-找规律】
- Ural 1180 Stone Game
- HDU4388 Stone Game II (找规律博弈)
- URAL 1180. Stone Game (博弈 + 规律)
- HDU 4388 Stone Game II 博弈,规律题
- Ural 1180. Stone Game
- URAL 1180. Stone Game (博弈 + 规律)
- HDU 4388 Stone Game II {博弈||找规律}
- URAL - 1243 - Divorce of the Seven Dwarfs (大数取模)
- hdu 1564 Play a game(博弈——找规律)
- 杭电1279 Stone Game(经典博弈)
- hdu 3389 Game(博弈——找规律)
- POJ 题目1740 A New Stone Game(博弈)
- UVALive 3668 A Funny Stone Game(博弈)
- 1180. Stone Game
- HDOJ1564Play a game(找规律博弈)