hdu4203 Doubloon Game-------sg 打表找规律
来源:互联网 发布:彩虹代刷3.9破解版源码 编辑:程序博客网 时间:2024/06/02 07:30
Doubloon Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 223 Accepted Submission(s): 136
Problem Description
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?
Input
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
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.
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.
Output
For every test case in the input, the output should contain one integer on a single line: the smallest number of coins that the player to move can take in order to secure the win. If there is no winning move, the output should be 0.
Sample Input
55 13 28 250 3100 10
Sample Output
10201
Source
BAPC 2011
Recommend
lcy
题意:两个海盗玩游戏。首先拿出一堆金币,金币数量为s。两人轮流从中取金币。规定一个正整数k,每次可以取的金币数量必须为k的乘方:1、k、k^2、k^3……。最后取完金币的人获胜。给出 s 和 k,求一个最小的值 a,使得取走 a 个金币后先手仍然是必胜的状态。
打表代码:
#include<iostream>#include<cstdlib>#include<stdio.h>#include<memory.h>#define ll __int64using namespace std;int b,minmin;ll fibo[110];bool flag;int dfs(int x){ if(x<0) return 0; for(int i=0;i<16;i++) { if(x-fibo[i]<0) break; if(dfs(x-fibo[i])==0) { return 1; } } return 0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&b); minmin=9999999; flag=true; fibo[0]=1; for(int i=1;i<=15;i++) fibo[i]=fibo[i-1]*b; for(int a=0;a<=10;a++) { if(dfs(a)) { for(int i=0;i<=15;i++) { if(a-fibo[i]>=0&&dfs(a-fibo[i])==0) { printf("%d ",fibo[i]); break; } } } else printf("0 "); } puts(""); }}
A题代码:
#include<iostream>#include<cstdlib>#include<stdio.h>using namespace std;int main(){ int t,a,b; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); int x=a%(b+1); if(b&1) { if(x%2==0) puts("0"); else puts("1"); } else { if(x<b) { if(x%2==1) puts("1");else puts("0"); } else printf("%d\n",b); } }}
- hdu4203 Doubloon Game-------sg 打表找规律
- hdu4203 Doubloon Game
- hdu 4203 Doubloon Game (SG规律)
- hdoj 4203 Doubloon Game(博弈+找规律)
- HDOJ 4203 Doubloon Game 博弈 找规律
- LightOJ-1296 Again Stone Game(SG打表找规律)
- hdu 4023 Doubloon Game(博弈)
- 博弈——Doubloon Game
- hdu_1517(SG函数+打表找规律)
- hdu 1079 Calendar Game(博弈SG函数 || 奇偶找规律)
- UVA 12293 Box Game 组合游戏/SG定理+找规律
- HDU 2147kiki's game(SG函数,找规律)
- Again Stone Game (通过SG函数找规律)
- HDU 1079 Calendar Game (奇偶规律,SG函数)*
- HDU 4203 Doubloon Game(博弈)
- Hdu 4203 Doubloon Game 博弈+打表
- hdu5795A Simple Nim(SG函数、打表找规律)
- zoj2290 Game----博弈 打表找规律
- 没有2,3,5,7以外的质因子的数的排序
- 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup
- ajax 页面模型
- Step By Step(C++模板推演)
- TTI
- hdu4203 Doubloon Game-------sg 打表找规律
- DBGridEh的Title(表头)动态赋值
- string、List<T>之类泛型定义
- 为什么opencv的canny函数检测边缘的效果和matlab的不同
- CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13+博客系统WordPress3.3.2
- [Android]Adb connection Error:远程主机强迫关闭了一个现有的连接。
- Step By Step(C++模板重载和特化)
- 如何将文件夹添加到 Visual Studio 2008 的现有工程上
- matlab用来度量图像区域属性的函数——regionprops