A Multiplication Game (博弈,规律)
来源:互联网 发布:head first java第2版 编辑:程序博客网 时间:2024/06/05 22:39
Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n.
Input
Each line of input contains one integer number n.
Output
For each line of input output one line either
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
Sample Input
162
17
34012226
Sample Output
Stan wins.
Ollie wins.
Stan wins.
题意:给一个正整数n(1 < n < 4294967295),p=1,S和O游戏,两人轮流对p乘以2-9之间的一个数,首先使p>=n的人获胜,每次游戏都从S开始
分析:与其说博弈,不如说是规律。。 这个题看着有点像Nim博弈,想着和9的倍数? 还是别的?
写了一个,发现不对
然后根据题意列几个出来
S胜:2-9 (0+2)——9
O胜:10-18 (9+1)——9*2
S胜:19-162 (2*9+1)——9*2*9
O胜:163-324 (9*2*9+1)——9*2*9*2
S胜:324-2916 (9*2*9*2+1)——9*2*9*2*9
……
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define mem(a,n) memset(a,n,sizeof(a))const double INF=0x3f3f3f3f+1.0;const double eps=1e-6;const double PI=2.0*acos(0.0);typedef long long LL;const int N=305;int main(){ LL n,tmp; while(~scanf("%lld",&n)) { if(n>1&&n<10) { puts("Stan wins."); continue; } LL ans=0,p=1; while(p<n) { // printf("p=%lld ans=%lld\n",p,ans); if(ans&1) p*=2; else p*=9; ans++; } printf("%s wins.\n",ans%2?"Stan":"Ollie"); } return 0;}
- A Multiplication Game 1517 (博弈+规律)
- A Multiplication Game (博弈,规律)
- POJ 2505 A multiplication game(找规律博弈)
- poj 2505 A multiplication game (博弈+找规律)
- A Multiplication Game (博弈)
- hdu 1517 A Multiplication Game(博弈找规律)
- 【POJ 2505】A multiplication game 博弈 - 找规律
- HDU 1517 A Multiplication Game(博弈找规律)
- A Multiplication Game + 博弈
- [博弈] A Multiplication Game
- A Multiplication Game 博弈
- HDU 1517 ——A Multiplication Game(博弈)(找规律)
- HDU 1517 A Multiplication Game (博弈、PN态、找规律)*
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game(规律)
- poj 2505 A multiplication game(博弈)
- HDU(1517)A Multiplication Game(博弈)
- HDU 1517 A Multiplication Game(博弈)
- SQL中在 inner join 子句中 加入top子句 文章1
- K-means和K-means++的算法原理及sklearn库中参数解释、选择
- static关键字
- 求出大家最喜欢吃的前k种水果(求数组中出现次数最多的)
- 接水问题
- A Multiplication Game (博弈,规律)
- Springboot项目使用aop切面保存详细日志到ELK日志平台
- spring的AOP概念理解
- python之helloword
- iOS中保持界面流畅的一些小技巧
- VIM编辑器命令大全
- [7-01]jvm
- ios-webView去加载静态的html
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 dp