hdu4203 Doubloon Game-------sg 打表找规律
2012-09-12 09:40
351 查看
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?
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.
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
5 5 1 3 2 8 2 50 3 100 10
Sample Output
1 0 2 0 1
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 __int64 using 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); } } }
相关文章推荐
- 尼姆博奕HDU 5795 A Simple Nim(SG打表找规律)
- HDU 3032 (SG打表找规律)
- UVA 1482 - Playing With Stones(SG打表规律)
- HDU 3032 Nim or not Nim? SG打表找规律
- hdu5795 A Simple Nim 求nim求法,打表找sg值规律 给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作可以选择任意一堆取走任意个石子(不可以为空) 或者选择一堆,把它分成三堆,每堆不为空。求先手必胜,还是后手必胜。
- UVA 1482 - Playing With Stones(SG打表规律)
- hdu3032 Nim or not Nim?-----sg打表找规律 允许把一堆石子分成两堆小的
- hdu3032 Nim or not Nim? SG打表找规律
- HDU 5795 A Simple Nim(SG打表找规律)
- hdu 5795 2016 Multi-University Training Contest 6(SG+打表找规律)
- hdu 5795 A Simple Nim(SG打表找规律)
- hdu 2147 kiki's game(DP(SG)打表找规律)
- LightOJ-1296 Again Stone Game(SG打表找规律)
- HDU 3032 Nim or not Nim?(博弈 SG打表找规律)
- hdu 3032 sg打表找规律 *
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- hdu 3032 Nim or not Nim? (SG打表找规律)
- HDU 3032 Nim or not Nim?(博弈,SG打表找规律)
- 1068 Bash游戏 V3 (sg打表找规律)
- HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)