FZUOJ-2275 Game
Problem 2275 GameAccept: 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
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<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的更多相关文章
- hdu 2275 Kiki & Little Kiki 1
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275 题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No ...
- HIT 2275 Number sequence
点击打开HIT 2275 思路: 树状数组 分析: 1 题目要求的是总共的搭配方式,满足Ai < Aj > Ak.并且i j k不同 2 我们开两个树状数组,第一个在输入的时候就去更新.然 ...
- hdu 2275 Kiki & Little Kiki 1 水题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2275 这个题比较简单,所以就没有测试样例提供给大家,基本把题目的样例过了就可以了 题目大意 给你一串操作, ...
- fzu Problem 2275 Game(kmp)
Problem 2275 Game Accept: 62 Submit: 165Time Limit: 1000 mSec Memory Limit : 262144 KB Proble ...
- HOJ——T 2275 Number sequence
http://acm.hit.edu.cn/hoj/problem/view?id=2275 Source : SCU Programming Contest 2006 Final Time li ...
- fzuoj Problem 2129 子序列个数
http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162 Submit: 491Time Limit: ...
- HOJ 2275 Number sequence
题意:问你有多少个序列满足Ai < Aj > Ak and i < j < k. 思路:对每个数求它之前和之后分别有多少个个数比它小,两边相乘.最后求和.具体实现先用树状数组正 ...
- fzuoj Problem 2179 chriswho
http://acm.fzu.edu.cn/problem.php?pid=2179 Problem 2179 chriswho Accept: 57 Submit: 136 Time Limi ...
- fzuoj Problem 2182 水题
http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188 Submit: 277Time Limit: 100 ...
- fzuoj Problem 2177 ytaaa
http://acm.fzu.edu.cn/problem.php?pid=2177 Problem 2177 ytaaa Accept: 113 Submit: 265Time Limit: ...
随机推荐
- 在父组件中,传值给子组件-vue
1.通过 props <x-test :name="username"></x-test>1)props为字符串数组 props: ['name']2)pr ...
- classloader加载class的流程及自定义ClassLoader
java应用环境中不同的class分别由不同的ClassLoader负责加载.一个jvm中默认的classloader有Bootstrap ClassLoader.Extension ClassLoa ...
- IIS部署复盘(杂记)
首先,230是网站服务器,231主要放到是数据库:所以在230(部署的服务器)上部署不需要部署IIS和Oracle数据库, 231呢?231是数据库服务器:百度一下数据库服务器是什么? 文档第五步: ...
- k-means原理和python代码实现
k-means:是无监督的分类算法 k代表要分的类数,即要将数据聚为k类; means是均值,代表着聚类中心的迭代策略. k-means算法思想: (1)随机选取k个聚类中心(一般在样本集中选取,也可 ...
- php array_pop()函数 语法
php array_pop()函数 语法 作用:删除数组中的最后一个元素.博智达 语法:array_pop(array) 参数: 参数 描述 array 必需.规定数组. 说明:返回数组的最后 ...
- HDU1232 畅通工程(并查集)
#include<iostream> using namespace std; ]; int findx(int x) { while(num[x]!=x)x=num[x]; return ...
- R语言预测实战(第二章--预测方法论)
2.1预测流程 从确定预测主题开始,一次进行数据收集.选择方法.分析规律.建立模型.评估效果直到发布模型. 2.2.1确定主题 (1)指标:表达的是数量特征,预测的结果也通常是通过指标的取值来体现. ...
- UE4中显示AI Debug信息
运行时,按下引号键('),就会出现AI的Debug信息,包含 AI Behavior Tree EQS Perception 四个大的分类,可以通过键盘上的1234键来显示和关闭相应的选项. 另外在E ...
- Swift equality
最后更新: 2017-07-23 在程序开发中,我们时常需要来判断两个对象是否相等.在编程思想中,两个对象相等指的是在内存中的地址相同,也就是两个指针指向同一个地址.但是在日常理解中,只要两个对象的内 ...
- WEB Fuzz中需要关注的7种响应
WEB应用模糊测试(WEB Fuzz)是一种特殊形式的网络协议模糊测试,专门关注遵循HTTP规范的网络数据包. WEB Fuzz并不是新的概念,目前有多种WEB应用模糊测试器(WEB Fuzzer), ...