fzu Problem 2275 Game(kmp)
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
Sample Output
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
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)
#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)的更多相关文章
- FZU - 1901 Period II (kmp)
传送门:FZU - 1901 题意:给你个字符串,让你求有多少个p可以使S[i]==S[i+P] (0<=i<len-p-1). 题解:这个题是真的坑,一开始怎么都觉得自己不可能错,然后看 ...
- FZU Problem 2221 RunningMan(贪心)
一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...
- poj2406 Power Strings(kmp)
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...
- String Problem - HDU 3374 (kmp+最大最小表示)
题目大意:有一个字符串长度为N的字符串,这个字符串可以扩展出N个字符串,并且按照顺序编号,比如串 ” SKYLONG “ SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGSKY ...
- POJ 2406 Power Strings(KMP)
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- LightOJ 1258 Making Huge Palindromes(KMP)
题意 给定一个字符串 \(S\) ,一次操作可以在这个字符串的右边增加任意一个字符.求操作之后的最短字符串,满足操作结束后的字符串是回文. \(1 \leq |S| \leq 10^6\) 思路 \( ...
- codeM编程大赛E题 (暴力+字符串匹配(kmp))
题目大意:S(n,k)用k(2-16)进制表示1-n的数字所组成的字符串,例如S(16,16)=123456789ABCDEF10: 解题思路: n最大50000,k最大100000,以为暴力会超时. ...
- 经典串匹配算法(KMP)解析
一.问题重述 现有字符串S1,求S1中与字符串S2完全匹配的部分,例如: S1 = "ababaababc" S2 = "ababc" 那么得到匹配的结果是5( ...
- URAL 1732 Ministry of Truth(KMP)
Description In whiteblack on blackwhite is written the utterance that has been censored by the Minis ...
随机推荐
- 3.1、Ubuntu系统中jmeter的安装和目录解析
以下内容亲测,如果不对的地方,欢迎留言指正,不甚感激.^_^祝工作愉快^_^ Jmeter是一个非常好用的压力测试工具. Jmeter用来做轻量级的压力测试,非常合适,只需要十几分钟,就能把压力测 ...
- PHP联接MySQL
<?php echo "This is a test</br>"; echo "asdfasdfadsf"; $mysql_server_na ...
- 【caffe】用训练好的imagenet模型分类图像
因为毕设需要,我首先是用ffmpeg抽取某个宠物视频的关键帧,然后用caffe对这个关键帧中的物体进行分类. 1.抽取关键帧的命令: E:\graduation design\FFMPEG\bin&g ...
- Android中C可执行程序编译问题
make:进入目录'/opt/FriendlyARM/tiny4412/android/android-4.1.2'make: *** 没有规则可以创建“out/target/product/gene ...
- kernel command line 参数详解
Linux内核在启动的时候,能接收某些命令行选项或启动时参数.当内核不能识别某些硬件进而不能设置硬件参数或者为了避免内核更改某些参数的值,可以通过这种方式手动将这些参数传递给内核. 如果不使用启动管 ...
- git分支合并脚本
为什么要写这个脚本 工作中经常会有合并分支的操作,一开始也不以为然,后来发现如果更新频繁的话,根本就停不下来,昨天上午正好有空,就完成了下面的这个初版 可能存在的问题 一般的应用场景都是:从maste ...
- Java 可重入锁
一般意义上的可重入锁就是ReentrantLock http://www.cnblogs.com/hongdada/p/6057370.html 广义上的可重入锁是指: 可重入锁,也叫做递归锁,指的是 ...
- Hibernate抽取BaseDao
package com.cky.dao; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate. ...
- 第八篇:Spark SQL Catalyst源码分析之UDF
/** Spark SQL源码分析系列文章*/ 在SQL的世界里,除了官方提供的常用的处理函数之外,一般都会提供可扩展的对外自定义函数接口,这已经成为一种事实的标准. 在前面Spark SQL源码分析 ...
- [Network Architecture]Xception 论文笔记(转)
文章来源 论文:Xception: Deep Learning with Depthwise Separable Convolutions 论文链接:https://arxiv.org/abs/161 ...