51nod-Bash游戏 V1V2V3V4

1066 Bash游戏

//自己小数据手推一下,可以找到规律的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int t,n,m;

void solve(int n,int m){
    printf("%c\n",n%(m+1)?'A':'B');
}

int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m;
        solve(n,m);
    }
    return 0;
}

1067 Bash游戏 V2

//先SG打表找规律
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max_n=110;

int t,n;
int sg[Max_n],f[Max_n];
bool s[Max_n];

void getSG(){
    int N=3;
    f[0]=1;f[1]=3,f[2]=4;
    sg[0]=0;
    for(int i=1;i<=100;i++){
        memset(s,0,sizeof(s));
        for(int j=0;f[j]<=i&&j<N;j++){
            s[sg[i-f[j]]]=1;
        }
        for(int j=0;j<=i;j++){
            if(!s[j]){sg[i]=j;break;}
        }
        cout<<i<<' '<<sg[i]<<endl;
    }
}

int main()
{
    //getSG();
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        if(n%7==0||n%7==2)puts("B");
        else puts("A");
    }
    return 0;
}

1068 Bash游戏 V3

//先SG打表找规律
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max_n=1100;

int t,n;
int sg[Max_n],f[Max_n];
bool s[Max_n];

void getSG(){
    int N;
    f[0]=1;
    for(int i=1;i<=100;i++){
        f[i]=f[i-1]*2;
        if(f[i]>Max_n){N=i;break;}
    }
    sg[0]=0;
    for(int i=1;i<=100;i++){
        memset(s,0,sizeof(s));
        for(int j=0;f[j]<=i&&j<N;j++){
            s[sg[i-f[j]]]=1;
        }
        for(int j=0;j<=i;j++){
            if(!s[j]){sg[i]=j;break;}
        }
        cout<<i<<' '<<sg[i]<<endl;
    }
}

int main()
{
    //getSG();
    scanf("%d",&t);
    char s[Max_n];
    while(t--){
        scanf("%s",s);
        int len=strlen(s);
        int sum=0;
        for(int i=0;i<len;i++)
            sum+=s[i]-'0';
        if(sum%3==0)puts("B");
        else puts("A");
    }
    return 0;
}

1070 Bash游戏 V4

//对于n,枚举所有取法,dfs找规律。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max_n=55;

int t,n;
int f[Max_n];

bool dfs(int x,int k){
    if(x==0)return false;
    for(int i=1;i<=x&&i<=k;i++){
        if(!dfs(x-i,i*2))
            return true;
    }
    return false;
}

int main()
{
//    for(int i=2;i<=100;i++){
//        int j;
//        for(j=1;j<i;j++){
//            if(dfs(i,j)){
//                //cout<<i<<' '<<'A'<<endl;
//                break;
//            }
//        }
//        if(j==i)cout<<i<<' '<<'B'<<endl;
//    }
    int ans=0;
    f[0]=1;f[2]=2;
    for(int i=2;i<100;i++){
        f[i]=f[i-1]+f[i-2];
        if(f[i]>1e9){ans=i;break;}
    }
    //cout<<ans<<endl;
    scanf("%d",&t);
    while(t--){
        cin>>n;
        if(binary_search(f,f+ans,n))puts("B");
        else puts("A");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值