Game FZU - 2275(KMP)

原创 2018年04月16日 21:45:39

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.


题意:一个是A,B玩游戏,给了A和B两个字符串(含义是数字)

可以进行两步操作,一是    倒置,二是    末尾/=10

而A和B进行博弈,A想尽量去匹配B的字符串,而B的却不想被A匹配

首先是分三种情况:

第一种:给定B的是0                    A

第二种:给定B的串比A的长       B

第三种:看B串的顺逆序后在不在A的串中。注意不是序列,而是字串。


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
void kmp_pre(char x[],int m,int next[])
{
    int i,j;
    j=next[0]=-1;
    i=0;
    while(i<m)
    {
        while(-1!=j && x[i]!=x[j])
            j=next[j];
        next[++i]=++j;
    }
}
int Next[10010];
int kmp_count(char x[],int m,char y[],int n)
{//x是模式串,y是主串
    int i,j;
    int ans=0;
    kmp_pre(x,m,Next);
    i=j=0;
    while(i<n)
    {
        while(-1!=j&&y[i]!=x[j])
            j=Next[j];
        i++;j++;
        if(j>=m)
        {
            ans++;
            j=Next[j];
        }
    }
    return ans;
}
int main()
{
    int T,n,m;
    cin>>T;
    while(T--){
        char x[100010],y[1000050];
        scanf("%s",x);
        scanf("%s",y);
        n=strlen(x);
        m=strlen(y);
        if(m==1&&y[0]=='0'){
            printf("Alice\n");
        }else if(n<m){
            printf("Bob\n");
        }else{
            if(kmp_count(y,m,x,n)){
                printf("Alice\n");
                continue;
            }
            reverse(y,y+m);
            if(kmp_count(y,m,x,n)){
                printf("Alice\n");
                continue;
            }
            printf("Bob\n");
        }
    }
    return 0;
}




【FZU - 2275 Game】 kmp

D - Game   Alice and Bob is playing a game. Each of them has a number. Alice’s number is A, a...
  • lyg_air
  • lyg_air
  • 2017-08-09 21:54:23
  • 196

FZU - 2275Game(KMP)

题目大意就是给Alice和Bob一人一个字符串,每个人每回合可以对自己的字符串进行两种操作中的一种,反转字符串或删除字符串末尾的那个数,字符串删完将变为“0” 正反KMP两次就好了,如果Alice的...
  • T__TSZ
  • T__TSZ
  • 2017-08-22 15:41:29
  • 81

FZU 2275 Game (KMP)

Problem 2275 Game Accept: 99    Submit: 270 Time Limit: 1000 mSec    Memory Limit : 262144 KB  P...
  • Mr_Treeeee
  • Mr_Treeeee
  • 2017-07-27 21:56:12
  • 502

fzu 2275 Game KMP

Problem 2275 Game Time Limit: 1000 mSec    Memory Limit : 262144 KB  Problem Description ...
  • u013491262
  • u013491262
  • 2017-07-25 09:48:46
  • 185

FZU 2275 Game(KMP)

http://acm.fzu.edu.cn/problem.php?pid=2275题目大意: A、B两个人玩一个游戏,现在他们各有一个数,并且分别都有两种选择:一种是把数反转,另一种是把数整除10...
  • feizaoSYUACM
  • feizaoSYUACM
  • 2017-08-23 16:19:48
  • 145

FZU 2275 - Game ( KMP字符串匹配 )

题意Alice和Bob玩游戏, 他们各自给出两个数字A, B ( 0
  • JinxiSui
  • JinxiSui
  • 2018-04-09 22:28:10
  • 7

【FZU - 2275 】Game 【KMP and 博弈】

Alice and Bob is playing a game.Each of them has a number. Alice’s number is A, and Bob’s number is ...
  • qq_37383726
  • qq_37383726
  • 2017-08-21 16:15:57
  • 88

fzu2275-kmp

此题的坑点例如 12312421352345 0 901 900 只要把b去尾巴的零,然后就...
  • a1325136367
  • a1325136367
  • 2017-07-24 18:36:04
  • 140

fzu 2282 Wand

Problem 2282 Wand Accept: 8    Submit: 24 Time Limit: 1000 mSec    Memory Limit : 262144 KB ...
  • threeh20
  • threeh20
  • 2017-07-23 13:18:22
  • 175

FZU 2275 Game【博弈】

Problem 2275 Game Accept: 70    Submit: 188 Time Limit: 1000 mSec    Memory Limit : 262144 KB  Pr...
  • Puyar_
  • Puyar_
  • 2017-07-24 16:17:13
  • 288
收藏助手
不良信息举报
您举报文章:Game FZU - 2275(KMP)
举报原因:
原因补充:

(最多只允许输入30个字)