Problem D Game

Accept: 145    Submit: 844
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.

题意:两个人操作各自的字符串,如果Alice通过有限的操作能得到和Bob一样的字符串,那么Alice赢,否则Bob赢

思路:仔细想想可以发现如果Bob的字符串如果是Alice的子串,那么Alice一定能通过有限的操作最终得到和Bob一样的字符串。

KMP字符串匹配即可,Alice的字符串以及其反串都判断一遍,注意在判断反串之前把反串中的前导0去掉。

AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int Next[+] = { };
/* P为模式串,下标从0开始 */
void GetNext(string P, int next[])
{
int p_len = P.size();
int i = ; //P的下标
int j = -;
next[] = -; while (i < p_len)
{
if (j == - || P[i] == P[j])
{
i++;
j++;
next[i] = j;
}
else
j = next[j];
}
} /* 在S中找到P第一次出现的位置 */
int KMP(string S, string P, int next[]){
GetNext(P, next); int i = ; //S的下标
int j = ; //P的下标
int s_len = S.size();
int p_len = P.size(); while (i < s_len && j < p_len)
{
if (j == - || S[i] == P[j]) //P的第一个字符不匹配或S[i] == P[j]
{
i++;
j++;
}
else
j = next[j]; //当前字符匹配失败,进行跳转
} if (j == p_len) //匹配成功
return i - j; return -;
}
string s1, s2;
int main(){
int t;
scanf("%d",&t);
while (t--) {
cin >> s1 >> s2;
if (KMP(s1, s2, Next) != -) { printf("Alice\n"); continue; }
else {
string tmp; bool flag = ; int k;
reverse(s2.begin(), s2.end());
for (k = ; k < s2.size();k++) //去掉前导0
if (s2[k] != '')break;
tmp = s2.substr(k, s2.size());
if (KMP(s1, tmp, Next) != -)printf("Alice\n");
else printf("Bob\n");
}
} return ;
}

foj Problem 2275 Game的更多相关文章

  1. fzu Problem 2275 Game(kmp)

    Problem 2275 Game Accept: 62    Submit: 165Time Limit: 1000 mSec    Memory Limit : 262144 KB  Proble ...

  2. FOJ ——Problem 1759 Super A^B mod C

     Problem 1759 Super A^B mod C Accept: 1368    Submit: 4639Time Limit: 1000 mSec    Memory Limit : 32 ...

  3. FOJ Problem 1016 无归之室

     Problem 1016 无归之室 Accept: 926    Submit: 7502Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  4. FOJ Problem 1015 土地划分

    Problem 1015 土地划分 Accept: 823    Submit: 1956Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  5. foj Problem 2107 Hua Rong Dao

    Problem 2107 Hua Rong Dao Accept: 503    Submit: 1054Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  6. foj Problem 2282 Wand

     Problem 2282 Wand Accept: 432    Submit: 1537Time Limit: 1000 mSec    Memory Limit : 262144 KB Prob ...

  7. FOJ Problem 2273 Triangles

    Problem 2273 Triangles Accept: 201    Submit: 661Time Limit: 1000 mSec    Memory Limit : 262144 KB P ...

  8. foj Problem 2283 Tic-Tac-Toe

                                                                                                    Prob ...

  9. FOJ Problem 2257 Saya的小熊饼干

                                                                                                        ...

随机推荐

  1. Dojo的declare接口

    declare(classname,[],{}) declare的第一个参数是可选的,代表类的名称 declare的第二个参数代表类的继承关系,比如继承哪一个父类,可以看到:第二个参数是一个数组,所以 ...

  2. 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串

      1.在<connectionStrings> 标签里添加连接 <connectionStrings> <add name="ConnectionName&q ...

  3. iOS开发中的Self-Manager 模式

    Self-Manager 源于我们团队内部的黑话,“诶?你刚去的创业公司有几个 iOS 开发啊?” “就我一个” “靠,你这是 Self-Manager 啊” 最近,这个思路被我们当做了一种设计模式, ...

  4. 对象、句柄、ID之间的区别

    对象是C++的概念,C++的类对象 句柄是Windows SDK的概念,指向某种资源的一种“指针”(有时候底层不一定是指针) 资源ID在MFC里仅仅是一个宏,也就是个整数. 其实,句柄是控件在数据结构 ...

  5. redis学习笔记(2)

    redis学习笔记第二部分 --配置文件介绍 二,解析redis的配置文件redis.conf常见配置参数说明redis.conf 配置项说明如下:1. Redis默认不是以守护进程的方式运行,可以通 ...

  6. Powershell 备忘

    如何修改环境变量 [environment]::SetEnvironmentvariable(“path”,"xxx","user") [environment ...

  7. 点击tr实现选择checkbox功能,点击checkobx的时候阻止冒泡事件, jquery给checkbox添加checked属性或去掉checked属性不能使checkobx改变状态

    给tr添加点击事件,使用find方法查找tr下的所有层级的元素,children只查找下一层级的元素,所以使用find.find的返回值为jquery对象,在这个项目中不知道为什么使用jquery给c ...

  8. Python基础学习总结__Day2

    一.模块初始 1.标准库模块: (1) Os模块 ① 和操作系统交互:例:执行命令代码 (2) Sys模块 ① 脚本+参数——>结果 2.第三方库模块:Django,Mysql... 存在E:\ ...

  9. day22-python之模块

    1.os import os # print(os.getcwd()) # os.chdir("..") # print(os.getcwd()) # os.makedirs('d ...

  10. Page-Object思想

    为什么要使用page-object 集中管理元素对象 集中管理一个page内的公共方法 后期维护方便 集中管理元素对象 实现方法: 调用方法: WebElement element = dri ...