zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    react-redux不完全指北
    ztext简单的介绍
    svg配合css多变形
    微服务异常感知与快速定位排错
    K8S(rancher) 服务(POD)定时重启服务方案
    记一次简单的微服务项目拆分
    K8S(rancher)Nginx Ingress Controller 负载均衡多路径问题解决方案
    15个必须知道的JavaScript数组方法
    python实现视频分帧
    python实现随机复制若干个文件到新目录
  • 原文地址:https://www.cnblogs.com/sz-wcc/p/11449193.html
Copyright © 2011-2022 走看看