FZU 2275 Game (KMP)
Accept: 99 Submit: 270
Time Limit: 1000 mSec Memory Limit : 262144 KB
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.
Source
第八屆福建省大學生程式設計競賽-重現賽(感謝承辦方廈門理工學院)題意很好懂。
POINT:
la<lb 肯定bob贏。 如果bob一開始就是0,alice贏。
其他情況就是判斷a串中有沒有串b或串反b,KMP裸題。
KMP模版是kuangbin的。
#include <stdio.h>
#include <iostream>
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;
scanf("%d",&T);
while(T--)
{
char x[100000+3];
char y[100000+3];
cin>>x>>y;
int m=strlen(x);
int n=strlen(y);
if(y[0]=='0'&&n==1){printf("Alice\n");continue;}
if(n>m) printf("Bob\n");
else
{
char yy[100000+3];
if(KMP_Count(y, n, x, m))
{
printf("Alice\n");
continue;
}
for(int i=0;i<n;i++)
{
yy[n-1-i]=y[i];
}
yy[n]='\0';
if(KMP_Count(yy, n, x, m))
{
printf("Alice\n");
continue;
}
printf("Bob\n");
}
}
}
相關文章
- FZU2150 Fire Game【BFS+暴力】GAM
- [LeetCode] 2275. Largest Combination With Bitwise AND Greater Than ZeroLeetCode
- KMPKMP
- KMP模板KMP
- kmp——板子~~~KMP
- 專題十六 KMP & 擴充套件KMP & Manacher【Kuangbin】KMP套件
- 【字串匹配】KMP字串匹配KMP
- KMP&exKMPKMP
- DP--m處理器問題- m processors(FZU - 1442)
- Card GameGAM
- Wooden GameGAM
- Shop GameGAM
- Guessing GameGAM
- KMP 自動機KMP
- KMP 演算法KMP演算法
- KMP演算法KMP演算法
- JAVA KMP 純模板JavaKMP
- Infinite Card GameGAM
- game development -- flowGAMdev
- Fast Car GameASTGAM
- Jump-gameGAM
- [筆記](更新中)KMP筆記KMP
- HDU 1711 Number Sequence(KMP)KMP
- 第三週下 kmpKMP
- 演算法之KMP演算法KMP
- 藍橋複習——KMPKMP
- Blue Jeans 【KMP+暴力】KMP
- KMP+狀態轉移KMP
- yang-xi-jie-mi-kmpKMP
- 菜狗的KMP學習KMP
- KMP(The Knuth-Morris-Pratt Algorithm)KMPGo
- KMP字串模式匹配詳解KMP字串模式
- 解讀KMP演算法KMP演算法
- KMP演算法詳解KMP演算法
- 白話 KMP 演算法KMP演算法
- 【演算法】KMP初識演算法KMP
- 軟工工程第二次結對作業《Fzu-help》軟工
- HDU 1729 Stone GameGAM