Problem 2275 Game

Accept: 159    Submit: 539
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

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

博弈问题,有两种操作,除10,或者反转,只要任何一方操作后,得到的两个数字相同,在有限步结束则Alice胜,否则Bob胜,
样例1:Alice不断除10,Bob只能除10或者反转,总会和Alice出现相同的情况;
样例2:Alice随意操作,Bob只需反转即可,而这不可能相同;
样例3:Alice反转即可;
样例4:不用操作,Alice胜;
可以看出,如果Bob的序列长度大于Alice,Alice肯定输,如果Bob的序列是Alice的子串,为了避免和Alice一致,只能除10,最后到0时Alice胜,如果不是子串,Bob不断反转即可,这就变成了子串匹配问题,可以用KMP算法,对Bob正匹配一次,反转匹配一次,要注意的是前导0,因为这个WA了。。。
#include<iostream>
#include<cstring>
#include<cstdio>
#define _match(a,b) ((a)==(b))
using namespace std;
const int N = + ;
typedef char elem_t;
char A[N],B[N],C[N];
int fail[N]; int pat_match(int ls,elem_t* str,int lp,elem_t* pat){
int i,j;
fail[] = -;
for(j=;j<lp;j++){
for(i=fail[j-];i>=&&!_match(pat[i+],pat[j]);i=fail[i]);
fail[j] = (_match(pat[i+],pat[j])?i+:-);
}
for(i=j=;i<ls && j<lp ;i++)
if(_match(str[i],pat[j]))
j++;
else if(j)
j=fail[j-]+,i--;
return j==lp?(i-lp):-;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",A);
scanf("%s",B);
int lena=strlen(A);
int lenb=strlen(B);
if(lena < lenb){printf("Bob\n"); continue;}
if(B[lenb-]=='') {printf("Alice\n"); continue;}
if(pat_match(lena,A,lenb,B)>=){printf("Alice\n");continue;}
int k=;
for(int i=lenb-;i>=;i--)
C[k++] = B[i];
k=;
while(C[k]=='') {k++;lenb--;}
if(pat_match(lena,A,lenb,C+k)>=){printf("Alice\n");continue;}
printf("Bob\n");
}
}

FZUOJ-2275 Game的更多相关文章

  1. hdu 2275 Kiki & Little Kiki 1

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275 题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No ...

  2. HIT 2275 Number sequence

    点击打开HIT 2275 思路: 树状数组 分析: 1 题目要求的是总共的搭配方式,满足Ai < Aj > Ak.并且i j k不同 2 我们开两个树状数组,第一个在输入的时候就去更新.然 ...

  3. hdu 2275 Kiki & Little Kiki 1 水题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2275 这个题比较简单,所以就没有测试样例提供给大家,基本把题目的样例过了就可以了 题目大意 给你一串操作, ...

  4. fzu Problem 2275 Game(kmp)

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

  5. HOJ——T 2275 Number sequence

    http://acm.hit.edu.cn/hoj/problem/view?id=2275 Source : SCU Programming Contest 2006 Final   Time li ...

  6. fzuoj Problem 2129 子序列个数

    http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162    Submit: 491Time Limit: ...

  7. HOJ 2275 Number sequence

    题意:问你有多少个序列满足Ai < Aj > Ak and i < j < k. 思路:对每个数求它之前和之后分别有多少个个数比它小,两边相乘.最后求和.具体实现先用树状数组正 ...

  8. fzuoj Problem 2179 chriswho

    http://acm.fzu.edu.cn/problem.php?pid=2179 Problem 2179 chriswho Accept: 57    Submit: 136 Time Limi ...

  9. fzuoj Problem 2182 水题

    http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188    Submit: 277Time Limit: 100 ...

  10. fzuoj Problem 2177 ytaaa

    http://acm.fzu.edu.cn/problem.php?pid=2177 Problem 2177 ytaaa Accept: 113    Submit: 265Time Limit: ...

随机推荐

  1. Vue Vue项目目录结构梳理

    Vue项目目录结构梳理   by:授客 QQ:1033553122 1.   结构梳理   . ├── build/                      # webpack 配置文件: │   ...

  2. Introduction of Generator in Python

    Python中生成器的原理与使用详解 原创牛大财有大才 发布于2018-09-05 14:36:38 0.range() 函数,其功能是创建一个整数列表,一般用在 for 循环中 语法格式:range ...

  3. D1. Kirk and a Binary String (easy version)

    D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后 ...

  4. 大数据笔记(十四)——HBase的过滤器与Mapreduce

    一. HBase过滤器 1.列值过滤器 2.列名前缀过滤器 3.多个列名前缀过滤器 4.行键过滤器5.组合过滤器 package demo; import javax.swing.RowFilter; ...

  5. php WebSocket 简单实现demo

    WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. WebSocket 使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据. 在 ...

  6. Spring整合Hibernate实现Spring Data JPA (介绍和使用)

    Spring Data JPA是Spring基于Hibernate开发的一个JPA框架.如果用过Hibernate或者MyBatis的话,就会知道对象关系映射(ORM)框架有多么方便. 但是Sprin ...

  7. Atcoder arc079 D Decrease (Contestant ver.) (逆推)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  8. h5离线缓存

    离线缓存:application cache 什么是离线缓存: 离线缓存可以将站点的一些文件缓存到本地,它是浏览器自己的一种机制,将需要的文件缓存下来,以便后期即使没链接网络,被缓存的页面也可以展示 ...

  9. Android手机fastboot 刷机命令【转】

    本文转载自:http://luke-feng.iteye.com/blog/2171090 简介:在安卓手机中fastboot是一种比recovery更底层的模式.fastboot是一种线刷,就是使用 ...

  10. Tomcat 的work 目录

    1    用tomcat作web服务器的时候,部署的程序在webApps下,这些程序都是编译后的程序(发布到tomcat的项目里含的类,会被编译成.class后才发布过来,源文件没有发布过来,但这里的 ...