51NOD 1068 Bash游戏 V3 (大数模板套用) 博弈


传送门:    点击打开链接(传送门)     https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1068


题目来源: Ural 1180
基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题
 收藏
 关注
有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量只能是2的正整数次幂,比如(1,2,4,8,16....),拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。
例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。(输入的N可能为大数)
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^1000)
Output
共T行,如果A获胜输出A,如果B获胜输出B。
Input示例
3
2
3
4
Output示例
A
B
A


数据N 10^1000  - - 大数 运算  套用模板  ;

也是一个规律题   先找规律,  每次只能拿1,2,4,8,16.... 2 的幂次方  


 也是 将每个N 来 分割成 1+X , 2+Y , 4+Z ,8+U,16+R  ....  等  根据前面的结果推后面的结果

 发现当时3的倍数的时候B 赢  则所以套用模板 就可以了啦 

#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <iostream>
#include <stdio.h>
#define ll long long

#define MAXN 10000
#define DELD 4

using namespace std;
int a[MAXN];
int b[MAXN];

struct Bignum{

    int len;
    int num[MAXN];
}y;
void Bigchar_int(string str)
{
    memset(y.num,0,sizeof(y.num));
    int len=str.length();
    int l=len/DELD;
    if(len%DELD)
        l++;
    y.len=0;
    for(int j=len-1;j>=0;j-=DELD)
    {
        int temp=0;
        int k=j-DELD+1;
        k=k<0?0:k;
        for(int x=k;x<=j;x++)
        {
            temp=temp*10+str[x]-'0';
        }
        y.num[y.len++]=temp;
    }
}
int Moduio()
{
    int i,d=0;
    for(i=y.len-1;i>=0;i--)
    {
        d=((d*MAXN)%3+y.num[i])%3;
    }
    if(d==0)
        printf("B\n");
    else
        printf("A\n");
}
int main()
{

    int T,n,i,j;
    string str;
    while(cin>>T)
    {
        while(T--)
        {
            cin>>str;
            Bigchar_int(str);
            Moduio();
            str.clear();
        }

    }
    return 0;
}



posted @ 2017-05-03 19:49  Sizaif  阅读(167)  评论(0编辑  收藏  举报