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 ;
}

最新文章

  1. 解决服务器每次都要输入Enter PEM pass phrase
  2. JS添加DOM元素CSS权重BUG
  3. Documentum常见问题11-xplore全文检索时找不到相关内容
  4. Android IOS WebRTC 音视频开发总结(六七)-- 在线教育虽火要做好其实不容易
  5. [AapacheBench工具]web性能压力测试工具的应用与实践
  6. 2014 Super Training #8 B Consecutive Blocks --排序+贪心
  7. Android计时器实例
  8. Stack and Heap 堆和栈的区别
  9. solrj-WiKi
  10. CentOS下modelsim 10.2c install &amp; crack
  11. UGUI-组件
  12. ios开发中如何实现软件版本更新
  13. Caused by: org.xml.sax.SAXParseException; systemId: file:/home/hadoop/hive-0.12.0/conf/hive-site.xml; lineNumber: 5; columnNumber: 2; The markup in the document following the root element must be well
  14. js 检测输入内容是否为空(小程序,网站)
  15. Salesforce Invoking Http Callouts and Testing Http Callouts
  16. FJUT3703 这还是一道数论题(二分 + hash + manacher 或者 STL + hash 或者 后缀数组 + hash)题解
  17. Flask + vue 前后端分离的 二手书App
  18. bzoj 4591 超能粒子炮&#183;改 - Lucas
  19. 桥接、nat、host-only
  20. win32api 找不到指定的模块

热门文章

  1. 无密码ssh操作步骤备忘
  2. Docker入门简明教程
  3. hive + hadoop 环境搭建
  4. 20145328 《Java程序设计》第5周学习总结
  5. vim 中查询和转换编码
  6. Centos为mysql开启binlog
  7. Mysql CASE WHEN 用法
  8. LA 3720 高速公路(互质判斜率)
  9. angular2中的路由转场动效
  10. java socket 判断Socket连接失效