博弈——Doubloon Game
来源:互联网 发布:广州优享网络 编辑:程序博客网 时间:2024/06/05 20:58
Being a pirate means spending a lot of time at sea. Sometimes, when there is not much wind, days can pass by without any activity. To pass the time between chores, pirates like to play games with coins.
An old favorite of the pirates is a game for two players featuring one stack of coins. In turn, each player takes a number of coins from the stack. The number of coins that a player takes must be a power of a given integer K (1, K, K^2, etcetera). The winner is the player to take the last coin(s).
Can you help the pirates gure out how the player to move can win in a given game situation?
An old favorite of the pirates is a game for two players featuring one stack of coins. In turn, each player takes a number of coins from the stack. The number of coins that a player takes must be a power of a given integer K (1, K, K^2, etcetera). The winner is the player to take the last coin(s).
Can you help the pirates gure out how the player to move can win in a given game situation?
One line with two integers S and K, satisfying 1 <= S <= 10^9 and 1 <= K <= 100: the size of the stack and the parameter K, respectively.
55 13 28 250 3100 10
10201
题意:给两个数s和k,代表有s个金币,每回合只能从这堆金币中取走k的自然数次幂个,谁取走最后一个金币,谁就赢。对于所给的s和n,求一开始最少拿多少个可以必胜,若没有必胜的走法输出0。
思路:
看这数据也是找规律,所以先打表
打表代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <queue>#include <algorithm>#include <vector>#include <stack>#define INF 0x3f3f3f3f#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long ll;const int maxn=10;ll a[maxn]; //存每次能取的石头数int dfs(int x){ if(x<0) return 0; for(int i=0; i<maxn; i++) { if(x<a[i]) return 0; if(dfs(x-a[i])==0) return 1; }}int main(){ int k; while(~scanf("%d", &k)) //输入k { a[0]=1; for(int i=1; i<maxn; i++) a[i]=a[i-1]*k; for(int i=0; i<=15; i++) //对s从0到15进行打表 { if(dfs(i)) { for(int j=0; j<maxn; j++) if(dfs(i-a[j])==0) { printf("%d ", a[j]); break; } } else printf("0 "); } printf("\n"); } return 0;}
打表后发现规律:
令x=s%(k+1);
如果k是奇数,判断s的奇偶性,如果是奇数则输出1,否则输出0
如果k是偶数,判断x是否等于k,是就输出k,否则判断x的奇偶性, 奇数输出1, 偶数输出0
AC代码
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <queue>#include <algorithm>#include <vector>#include <stack>#define INF 0x3f3f3f3f#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;int main(){ int t; scanf("%d", &t); while(t--) { int a, b; scanf("%d%d", &a, &b); int x=a%(b+1); if(b&1) { if(a&1) printf("1\n"); else printf("0\n"); } else { if(x<b) { if(x&1) printf("1\n"); else printf("0\n"); } else printf("%d\n", b); } } return 0;}
阅读全文
0 0
- 博弈——Doubloon Game
- hdu 4023 Doubloon Game(博弈)
- hdoj 4203 Doubloon Game(博弈+找规律)
- HDU 4203 Doubloon Game(博弈)
- HDOJ 4203 Doubloon Game 博弈 找规律
- Hdu 4203 Doubloon Game 博弈+打表
- HDU 4203 Doubloon Game(博弈打表)
- hdu4203 Doubloon Game
- 博弈——Calendar Game
- 博弈——Bomb Game
- poj 1082 Calendar Game——博弈
- 博弈——Play a game
- 博弈——kiki's game
- hdu4203 Doubloon Game-------sg 打表找规律
- hdu 4203 Doubloon Game (SG规律)
- hdu1851_A Simple Game博弈—SG函数
- ACM-巴什博弈之Brave Game——hdu1846
- ACM-博弈之Play a game——hdu1564
- 机器学习分类算法——集成学习
- 高级拖拽
- hdu 1241 dfs求连通块
- tomcat发布多个项目
- 正睿OI 2017冲刺T1Wa掉有点忧伤........
- 博弈——Doubloon Game
- 2072删数问题
- RQNOJ 188 购物问题
- python3 云词(wordcloud)安装失败解决方案
- codeforces 845A Chess Tourney
- Android native和h5混合开发几种常见的hybrid通信方式
- Redhat 7将网卡名称eno16777736改为eth0
- 献给30岁之前为前途迷茫彷徨的男人们的忠告
- 非常好的理解遗传算法的例子