zoukankan      html  css  js  c++  java
  • Game FZU

    Alice and Bob is playing a game.

    Each of them has a number. Alice’s number is A, and Bob’s number is B.

    Each turn, one player can do one of the following actions on his own number:

    1. Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321

    2. Divide. X = X/10. Attention all the numbers are integer. For example X=123456 , after this action X become 12345(but not 12345.6). 0/0=0.

    Alice and Bob moves in turn, Alice moves first. Alice can only modify A, Bob can only modify B. If A=B after any player’s action, then Alice win. Otherwise the game keep going on!

    Alice wants to win the game, but Bob will try his best to stop Alice.

    Suppose Alice and Bob are clever enough, now Alice wants to know whether she can win the game in limited step or the game will never end.

    Input

    First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

    For each test case: Two number A and B. 0<=A,B<=10^100000.

    Output

    For each test case, if Alice can win the game, output “Alice”. Otherwise output “Bob”.

    Sample Input

    4
    11111 1
    1 11111
    12345 54321
    123 123
    

    Sample Output

    Alice
    Bob
    Alice
    Alice
    

    Hint

    For the third sample, Alice flip his number and win the game.

    For the last sample, A=B, so Alice win the game immediately even nobody take a move.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cmath>
    #include<utility>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #include<stack>
    #define maxn 100010
    #define INF 0x3f3f3f3f
    #define LL long long
    #define ULL unsigned long long
    #define E 1e-8
    #define mod 1000000007
    #define P pair<int,int>
    using namespace std;
    
    int t,n,m;
    char a[maxn],b[maxn],c[maxn];
    int Next[maxn];
    void makeNext()
    {
        int q=0,k=-1;
        Next[0]=-1;
        while(q<m){
            if(k==-1||b[q]==b[k]) Next[++q]=++k;
            else k=Next[k];
        }
    }
    int kmp()
    {
        int i=0,q=0;
        makeNext();
        while(i<n&&q<m){
            if(q==-1||a[i]==b[q]){
                i++;
                q++;
            }
            else q=Next[q];
        }
        if(q==m) return i-m+1;
        else return -1;
    }
    
    
    int main()
    {
        scanf("%d",&t);
        while(t--){
            cin>>a>>b;
            n=strlen(a);
            m=strlen(b);
            if(m==1&&b[0]=='0'){
                printf("Alice
    ");
            }
            else if(n<m){
                printf("Bob
    ");
            }
            else{
                if(kmp()!=-1){
                    printf("Alice
    ");
                }
                else{
                    for(int i=0;i<m;i++){
                        c[m-i-1]=b[i];
                    }
                    for(int i=0;i<m;i++){
                        b[i]=c[i];
                    }
                    if(kmp()!=-1){
                        printf("Alice
    ");
                    }
                    else printf("Bob
    ");
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    剑指offer字符串列表
    剑指offer数组3
    剑指offer数组2
    剑指offer数组1
    剑指offer数组列表
    tensorflow+ssd_mobilenet实现目标检测的训练
    Win7+keras+tensorflow使用YOLO-v3训练自己的数据集
    Java是如何实现跨平台的
    Xshell 、PuTTY 复制文件到Linux
    Asp.Net Core2.0在linux下发布
  • 原文地址:https://www.cnblogs.com/upstart/p/8982319.html
Copyright © 2011-2022 走看看