51Nod1070 Bash游戏 V4

Problem

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量最少1个,最多不超过对手上一次拿的数量的2倍(A第1次拿时要求不能全拿走)。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。

例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。

Solution

打表写了半天,等我看明白怎么证回来补。

Code

#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x7fffffffffffffff
#define mem(a, x) memset(a,x,sizeof(a))
#define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
ll power(ll a, ll b,ll p) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % p; a = a * a % p; } return res; }
ll gcd(ll p, ll q) { return q == 0 ? p : gcd(q, p % q); }
ll _abs(ll x){return x < 0 ? -x : x;}
using namespace std;
int T,n;
bool fg;
int dfs(int cur,int cnt){
    if(cur==0) return 0;
    if(cur==1) return 1;
    if(cur==2) return 1;
    bool fg2=fg;
    fg=false;
    for(int i=1;i<=min(2*cnt,cur);i++){

        if(fg2&&i==cur) break;//cout<<"*"<<i<<"*"<<endl;
        if(!dfs(cur - i, i)) return 1;
    }
    return 0;
}
ll s[120]={0,1,1,2,3};
int main(){
    io_opt;
    /*for(int i=1;i<=100;i++){
        //if(i==3)cout<<"!!!"<<endl;
        fg=true;
        if(i!=2) cout<<i<<":"<<dfs(i,9999)<<endl;
        else{
            cout<<"2:0
";
        }
        //if(i==3) cout<<"!!!"<<endl;
    }*/
    for(int i=5;i<=100&&s[i-1]<10000000000;i++){
        s[i]=s[i-1]+s[i-2];
    }
    cin>>T;
    while(T--){
        cin>>n;
        bool k=false;
        for(int i=2;i<=100;i++){
            if(s[i]==n){
                k=true;
                break;
            }
        }
        if(k){
            cout<<"B
";
        }
        else{
            cout<<"A
";
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/sz-wcc/p/11449193.html