Problem 2275 Game

Accept: 62    Submit: 165
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

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.

 Source

第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)

 
题解:kmp
          如果b的位数大于a,B获胜。如果B为0,A获胜。如果b是a的逆序,A获胜,其他情况,如果b是a或者逆序a的子串,A获胜。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char s[],t[],tmp[];
int nextl[];
int ls,lt;
void getnext()
{
nextl[]=-;
for(int i=;i<lt;i++)
{
int j=nextl[i-];
while(t[j+]!=t[i]&&j>-)
j=nextl[j];
nextl[i]=(t[j+]==t[i])?j+:-;
}
}
int kmp(char *a,char *b)
{
getnext();
int sum=,i=,j=;
while(i<ls&&j<lt)
{
if(j==-||a[i]==b[j])
i++,j++;
else
j=nextl[j];
}
if(j==lt)
return ;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s%s",&s,&t);
ls = strlen(s);
lt = strlen(t);
if (lt>ls) { printf("Bob\n"); continue; }
if(kmp(s,t) || !strcmp(t,"")) {printf("Alice\n"); continue;} //如果t字符串是0,那么一定是Alice赢
reverse(t,t+lt); //这个翻转用法第一次碰到
if(kmp(s,t)) {printf("Alice\n"); continue;}
printf("Bob\n");
}
return ;
}

fzu Problem 2275 Game(kmp)的更多相关文章

  1. FZU - 1901 Period II (kmp)

    传送门:FZU - 1901 题意:给你个字符串,让你求有多少个p可以使S[i]==S[i+P] (0<=i<len-p-1). 题解:这个题是真的坑,一开始怎么都觉得自己不可能错,然后看 ...

  2. FZU Problem 2221 RunningMan(贪心)

    一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...

  3. poj2406 Power Strings(kmp)

    poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...

  4. String Problem - HDU 3374 (kmp+最大最小表示)

    题目大意:有一个字符串长度为N的字符串,这个字符串可以扩展出N个字符串,并且按照顺序编号,比如串  ” SKYLONG “ SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGSKY ...

  5. POJ 2406 Power Strings(KMP)

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

  6. LightOJ 1258 Making Huge Palindromes(KMP)

    题意 给定一个字符串 \(S\) ,一次操作可以在这个字符串的右边增加任意一个字符.求操作之后的最短字符串,满足操作结束后的字符串是回文. \(1 \leq |S| \leq 10^6\) 思路 \( ...

  7. codeM编程大赛E题 (暴力+字符串匹配(kmp))

    题目大意:S(n,k)用k(2-16)进制表示1-n的数字所组成的字符串,例如S(16,16)=123456789ABCDEF10: 解题思路: n最大50000,k最大100000,以为暴力会超时. ...

  8. 经典串匹配算法(KMP)解析

    一.问题重述 现有字符串S1,求S1中与字符串S2完全匹配的部分,例如: S1 = "ababaababc" S2 = "ababc" 那么得到匹配的结果是5( ...

  9. URAL 1732 Ministry of Truth(KMP)

    Description In whiteblack on blackwhite is written the utterance that has been censored by the Minis ...

随机推荐

  1. NGUI制作 《九宫格》 图片

    什么是九宫格图片? 就是一张图片的上下左右四个角是固定的,无论X/Y被拉伸多大,图片都不会失真 效果图 ------> 那在NGUI里面怎么做到呢 1 首先你要把图片添加到NGUI图集里,点击E ...

  2. 50条常用liunx命令整理

    1.pwd命令 :确定自己在那个目录 使用方法:在liunx命令输入框里面输入pwd,自动就会显示出自己现在在那个目录下 操作截图: 此时正处在root目录里面 2.cd命令:切换目录的意思 使用方法 ...

  3. python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)

    pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...

  4. 【Beginning Python】抽象(未完)

    [懒惰即是美德] 抽象意味着良好的可读性:说明你在努力做什么,而不是给出你正在如何做的细节. [抽象和结构] 程序应该是非常抽象的,就像“下载网页.计算频率.打印每个单词的频率”一样易懂.翻译成程序就 ...

  5. [NOI2014]起床困难综合症(二进制+贪心)

    题目 [NOI2014]起床困难综合症 做法 先用全\(0\)和全\(1\)去运行一下,再在满足\(m\)的限制下,贪心地从高位到低位选择即可

  6. Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date)

    Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date) 原因分析: ...

  7. Codeforces 235C. Cyclical Quest

    传送门 写的时候挺蛋疼的. 刚开始的时候思路没跑偏,无非就是建个SAM然后把串开两倍然后在SAM上跑完后统计贡献.但是卡在第二个样例上就是没考虑相同的情况. 然后开始乱搞,发现会出现相同串的只有可能是 ...

  8. 20145331《Java程序设计》课程总结

    20145331<Java程序设计>课程总结 每周读书笔记链接汇总 •20145331<Java程序设计>第一周学习总结 •20145331<Java程序设计>第二 ...

  9. 20145240《网络对抗》PC平台逆向破解_advanced

    PC平台逆向破解_advanced shellcode注入 Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限.另外,Shellcode一般是 ...

  10. 10个足以让你成为更优秀的程序员的C语言资源

    一些人觉得编程无聊,一些人觉得它很好玩.但每个程序员都必须紧跟编程语言的潮流.大多数程序员都是从C开始学习编程的,因为C是用来写操作系统.应用程序最常用的语言. · C编程笔记 这些是华盛顿实验学院C ...