题目:
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:
- Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321
- 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 11
1 11111
2345 54321
123 123
Sample output:
Alice
Bob
Alice
Alice
题意请自行百度翻译
题解:
可以看出,只要Bob的串是Alice的子串或是Alice串翻转的字串,Alice总能使自己的串与Bob的串相同,于是可以看出是一个裸kmp题。
但是还有一个特判,就比如说Bob串只有一个‘0’,而Alice串中没有‘0’,这也是Alice赢(就被这里坑了)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<int> q;
stack<int> s;
priority_queue<int> pq;
const int maxn = 100005;
ll n,m,l,r;
ll ans=0;
ll a[maxn];
ll next[maxn];
ll dp[maxn];
void getnext(string a)
{
ll len=a.size();
ll i=0,j=-1;
next[0]=-1;
while(i<len){
if(j==-1||a[i]==a[j]){
next[++i]=++j;
}
else j=next[j];
}
}
ll kmp(string a,string b)
{
ll lena=a.size();
ll lenb=b.size();
ll i=0,j=0;
while(i<lena&&j<lenb){
if(j==-1||a[i]==b[j]){
j++;
i++;
}
else
j=next[j];
}
if(j==lenb)
return 1; //如果是字串则返回1
else
return 0;
} //以上两个函数是用于kmp字符串匹配的,判断是否是字串
int main()
{
ll T;
cin>>T;
while(T--){
string s,f,s0;
cin>>s>>f;
s0=s;
reverse(s.begin(),s.end());
//cout<<s<<endl<<s0<<endl;
getnext(f);
if((kmp(s,f)||kmp(s0,f))&&s.size()>=f.size())
cout<<"Alice\n";
else if(f.size()==1&&f[0]=='0'){ //这个特判真的要命
cout<<"Alice\n";
}
else
cout<<"Bob\n";
}
}