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");
}
}
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: ...
随机推荐
- Flask【第3篇】:蓝图、基于DBUtils实现数据库连接池、上下文管理等
基于DBUtils实现数据库连接池 小知识: 1.子类继承父类的三种方式 class Dog(Animal): #子类 派生类 def __init__(self,name,breed, life_v ...
- 无法启动链接服务器"XXX DB Link"的 OLE DB 访问接口 "SQLNCLI11" 的嵌套事务。由于 XACT_ABORT 选项已设置为 OFF,因此必须使用嵌套事务。链接服务器"XXX DB Link"的 OLE DB 访问接口 "SQLNCLI11" 返回了消息"无法在此会话中启动更多的事务"。
无法启动链接服务器"XXX DB Link"的 OLE DB 访问接口 "SQLNCLI11" 的嵌套事务.由于 XACT_ABORT 选项已设置为 OFF,因 ...
- 如何在ASP.NET Core中上传超大文件
HTML部分 <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="index.aspx. ...
- Vue中v-for配合使用Swiper插件问题
问题描述: 在一个页面中需要一个用swiper的轮播图,数据大概有40条,每一屏幕的swiper只显示其中的n条数据. 代码描述: <div id="app"> < ...
- rman备份/恢复
全备脚本 cat rman_full.sh #!/bin/bash export ORACLE_BASE=/opt/oracle export ORACLE_HOME=$ORACLE_BASE/pro ...
- WinSetupFromUSB - 超简单制作多合一系统安装启动U盘的工具 (支持Win/PE/Linux启动盘)
很多同学都喜欢将电脑凌乱不堪的系统彻底重装以获得一个"全新的开始",但你会发现如今很多电脑都已经没有光驱了,因此制作一个U盘版的系统安装启动盘备用是非常必要的. 我们之前推荐过 I ...
- 大数据笔记(二十一)——NoSQL数据库之Redis
一.Redis内存数据库 一个key-value存储系统,支持存储的value包括string(字符串).list(链表).set(集合).zset(sorted set--有序集合)和hash(哈希 ...
- 【30分钟学完】canvas动画|游戏基础(1):理论先行
前言 本文虽说是基础教程,但这是相对动画/游戏领域来说,在前端领域算是中级教程了,不适合前端小白或萌新.阅读前请确保自己对前端三大件(JavaScript+CSS+HTML)的基础已经十分熟悉,而且有 ...
- git 指定从其他分支拉取commit
git cherry-pick commit-id (github 上的短号)
- picker组件 label组件讲解
label组件:包住表单的组件,将里面的表单和label里的元素,紧紧的包在一起,当触发label里的元素,就相当于触发了表单组件 属性:for:类型 字符串 表单的 id 的值 picker组件:是 ...