Game

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
题解:此题分为3种情况。
(1):如果strlen(a)<strlen(b),Bob win;
(2):如果b=='0',Alice win;
(3) :如果b是a的子串||reverse(b)是a的子串 Alice win,反之 Bob win;(kmp 裸题);
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 int m1,d;
 7 char a[1000000],b[1000000];
 8 int f[1000001];
 9 void getnt()
10 {
11     memset(f,'0',sizeof(f));
12     int i=0,j=-1;
13     f[0]=-1;
14     while(i<d)
15     {
16         if(j==-1||b[i]==b[j])
17         {
18             i++;j++;
19             if(b[i]!=b[j])
20                 f[i]=j;
21             else
22                 f[i]=f[j];
23         }
24         else
25             j=f[j];
26 
27     }
28 }
29 int kmp()
30 {
31     getnt();
32     int i=0, j=0;
33     while(i<d)
34     {
35         if(j==-1||a[i] ==b[j])
36             i++, j++;
37         else
38             j=f[j];
39         if(j==m1)
40             return i-m1+1;
41     }
42     return -1;
43 }
44 int main()
45 {
46     int T,flog;
47     scanf("%d",&T);
48     for(int i=0;i<T;i++)
49     {
50         scanf(" %s %s",&a,&b);
51         if(b[0]=='0')
52             printf("Alice\n");
53         else
54         {
55         if(strlen(a)<strlen(b))
56             printf("Bob\n");
57         else
58         {
59             char p;
60             m1=strlen(b);
61             d=strlen(a);
62             flog=kmp();
63             if(flog==-1)
64             {
65                 for(int j=0;j<m1/2;j++)
66                 {
67               swap(b[j],b[m1-j-1]);                      
68               }
69                 flog=kmp();
70             }
71             if(flog==-1)
72                 printf("Bob\n");
73             else
74                 printf("Alice\n");
75         }
76         }
77     }
78     return 0;
79 }

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.

猜你喜欢

转载自www.cnblogs.com/moomcake/p/8975856.html