您的位置:首页 > 其它

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);
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: