FZUOJ-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
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");
}
}
最新文章
- Hibernatel框架关联映射
- Mysql查看执行计划-explain
- XML解析工具类
- 关于silverlight打印模糊的问题
- 10TSQL语言概述-脚本调试-命名规范-天轰穿数据库2014
- CAPI3 HTTP文件服务器搭建(共享目录版)
- IE6、IE7、IE8中overflow:hidden无效问题
- web工程中URL地址的写法
- Borland license information was found,but it is not valid for delphi.
- 如何将js与HTML完全脱离
- Oracle Dedicated server 和 Shared server(专用模式 和 共享模式) 说明(转)
- 中国还是和AMD走到一起了 但美国会高兴吗(网易科技 卢鑫)
- JAVA 命令行参数解析,org.apache.commons.cli的使用
- EasyUI Tree 树 ——实现多级别菜单的展示,以及与后台数据的交互
- [Css] css3的flex布局
- flask 数据库迁移的简单操作
- Python数据库连接池DBUtils
- 苹果审核被拒,解析奔溃日志.txt转crash文件
- Linux下安装解压版(tar.gz)MySQL5.7
- PHP实现IP访问限制及提交次数的方法详解