hust 1366 Game

1366 - Game

Time Limit: 1s Memory Limit: 256MB

Submissions: 267 Solved: 16
DESCRIPTION
Alice and Bob is playing a game, there N coins in a pile. Alice goes first, she can take away one coin at least, and N-1 coins at most. After that, Bob and Alice move away coins in turn, every time he (she) can take away one to twice of previous one. Assume there are 20 coins, Alice take away 4 coins first, then Bob can take 1 to 8 coins. If Bob takes away 5 coins, then Alice can take 1 to 10 coins next. The one who take the last coin Win. You can suppose that Alice and Bob are so cleaver that they can always do their best to Win.
INPUT
The first line of the input is an integer T, the number of test cases. For each case, is a line with an integer N, the number of coins. (N < 264)
OUTPUT
For each case, if Alice lose, just output “Alice Lose”, and if Alice win, please output “Alice Win”, and inform the minimum number of coins Alice should take away in the first turn, as the sample output.
SAMPLE INPUT
4
2
5
10
14
SAMPLE OUTPUT
Alice Lose
Alice Lose
Alice Win, take 2 coins first
Alice Win, take 1 coins first
HINT
SOURCE

中国地质大学(武汉)第七届ACM程序设计大赛暨华中地区部属高校ACM邀请赛


既然是先手操作那么每次的才做都是把对方往必败态推。。

已知的必败态有 2  3

那么由题意可知下个必败态就是 5(取1 后手进入必胜态,,取2后手直接就取完了,,也不多bb)

然后就是 8

通过这个可以推出 f【i】=f【i-1】+f【i-2】

求最开始的最小取值

#include<stdio.h>
#include<string.h>
#define ll unsigned long long
ll dp[1003];
int main()
{
    dp[1]=2;
    dp[2]=3;
    for(int i=3;i<=91;i++)
    {
        dp[i]=dp[i-1]+dp[i-2];
    }
    //printf("%llu\n",dp[91]);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll n;
        scanf("%llu",&n);
        int flag=0;
        ll m=n;

        for(int i=91;i>=1;i--)
        {
            if(dp[i]<n)
            {
                n-=dp[i];
                flag=1;
            }
            else if(dp[i]==n)
            {
                break;
            }
        }
        if(flag&&n!=m)
            printf("Alice Win, take %llu coins first\n",n);
        else printf("Alice Lose\n");
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值