Problem Description
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
Sample Output
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.
题意:Alice简化为A,Bob简化为B,A,B各有2个属于他们自己的数字,通过2种方法 1.数字串翻转,2.数字串/10,且仍为整数,A先B后,判断A是否可以与B相同,如果可以A 赢 否则B赢。
思路:判断是否为子串,如果是倒叙的子串也可以。
附上水过数据弱的代码:
- #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char a[1000005],b[1000005];
int suma[15],sumb[15];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s%s",a,b);
int la=strlen(a),lb=strlen(b),flag=1;
memset(suma,0,sizeof(suma)); //将数组suma初始化为0
memset(sumb,0,sizeof(sumb));
if(la>=lb&&flag)
{
for(int i=0;i<la;i++)
suma[a[i]-'0']++; //将字符型转化为整形
for(int i=0;i<lb;i++)
sumb[b[i]-'0']++;
for(int i=0;i<=9;i++){
if(suma[i]<sumb[i]){ //i字符的个数
flag=0;
break;
}
}
if(sumb[0]>0)
{
for(int i=1;i<=9;i++){
if(sumb[i]==0){
flag=1;
break;
}
}
}
}
else
flag=0;
if(flag)
printf("Alice\n");
else
printf("Bob\n");
}
return 0;
}