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. VS Code:设置多行注释快捷键

    多行注释,也叫块注释. 如何查看,并修改VS Code中的多行注释快捷键呢? 1). 点击 首选项 - 键盘快捷方式 2). 在搜索框中输入 comment 3). 这个时候可以看到“切换块注释”的信 ...

  2. 第四次作业:Windows各种基本应用的命令处理方法

    删除文件夹命令? rd (remove directory) 如何给文件夹重新命名? ren (rename) 如何在文件夹中建立文件夹? md swift\a 如何用命令查看文本文件的内容? typ ...

  3. React入门教程(二)

    前言 距离上次我写 React 入门教程已经快2个月了,年头年尾总是比较忙哈,在React 入门教程(一)我大概介绍了 React 的使用和一些注意事项,这次让我们来继续学习 React 一. Rea ...

  4. SAP HANA

    DROP PROCEDURE ""."ZCONCAT_EKKO_EBN"; CREATE PROCEDURE ""."ZCONCA ...

  5. Go IO && bufio

    IO IO包 是对数据流的操作.从哪里来, 怎么处理,再到哪里去. 图片来源 https://medium.com/learning-the-go-programming-language/strea ...

  6. python3 连接 mysql和mariadb的模块

    是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm

  7. console_init()分析

    启动阶段初始化控制台流程分析, start_kernel console_init(); -->tty_ldisc_begin(); /* Setup the default TTY line ...

  8. centos7 bond 和 网桥配置

    rhel7系统bond配置(更新版本):https://www.cnblogs.com/zhangjianghua/p/9119808.html Bonding的模式一共有7种: 1.mode=0(b ...

  9. Spring核心技术(十三)——环境的抽象

    本章将描述一下Spring中针对环境的抽象. Environment是一个集成到容器之中的特殊抽象,它针对应用的环境建立了两个关键的概念:profile和properties. profile是命名好 ...

  10. python基础学习笔记——反射

    对编程语言比较熟悉的朋友,应该知道“反射”这个机制.Python作为一门动态语言,当然不会缺少这一重要功能.然而,在网络上却很少见到有详细或者深刻的剖析论文.下面结合一个web路由的实例来阐述pyth ...