CSU - 2056 a simple game
Description
这一天,小A和小B在玩一个游戏,他俩每人都有一个整数,然后两人轮流对他们的整数进行操作,每次在下列两个操作任选一个:
(1)对整数进行翻转,如1234翻转成4321 ,1200翻转成21
(2)将整数除以10,如1234/10=123,1/10=0
当操作过程中出现a==b时,则小A就赢了,而操作一直进行下去或不能使a==b则算小B赢。
现在小A求助于你,想让你帮他在知道两人的整数时小A能不能赢,假设每次都是小A先手,并且两人都是采取最优策略
Input
首先输入T(T <= 100),表示有T组数据,然后接下来有T行,每行有两个整数a,b(0 <= a,b < 10100000)
Output
有T行,当小A赢了则输出"Yes",否则输出"No"
Sample Input
4
1234 123
123 321
1234 12345
123 123
Sample Output
Yes
Yes
No
Yes
Hint
Source
Author
wsf
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
#define MAXN 100010
int n,m;
int slen,tlen;
char s[MAXN],t[MAXN];
int nextt[MAXN];
bool flag; void GetNext()
{
int j = 0; nextt[1] = 0;
for (int i = 2; i <= tlen; i++)
{
while (t[i] != t[j + 1] && j > 0)
j = nextt[j];
if (t[i] == t[j + 1])
j++;
nextt[i] = j;
}
} int main()
{
int T;
while (~scanf("%d", &T))
{
while (T--)
{
scanf("%s%s", s + 1, t + 1);
slen = strlen(s + 1);
tlen = strlen(t + 1);
while (s[slen] == '0'&&slen > 1)
s[slen--] = '\0';
while (t[tlen] == '0'&&tlen > 1)
t[tlen--] = '\0';
int j = 0; flag = false;
GetNext();
for (int i = 1; i <= slen; i++)
{
while (s[i] != t[j + 1] && j > 0)
{
j = nextt[j];
}
if (s[i] == t[j + 1] && j + 1 <= tlen)
j++;
if (j == tlen)
flag = true;
}
reverse(t + 1, t + tlen+1);
GetNext();
j = 0;
for (int i = 1; i <= slen; i++)
{
while (s[i] != t[j + 1] && j > 0)
j = nextt[j];
if (s[i] == t[j + 1] && j + 1 <= tlen)
j++;
if (j == tlen)
flag = true;
}
if (flag)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
CSU - 2056 a simple game的更多相关文章
- CSU 2056 a simple game (正反进行KMP)超级好题!!!
Description 这一天,小A和小B在玩一个游戏,他俩每人都有一个整数,然后两人轮流对他们的整数进行操作,每次在下列两个操作任选一个: (1)对整数进行翻转,如1234翻转成4321 ,1200 ...
- Water --- CSU 1550: Simple String
Simple String Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...
- D - Simple String CSU - 1550
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz, 但是这题只需要简 ...
- CSU - 1550 Simple String —— 字符串
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 题解: 1.A+B 与C的交集必须>=n 2.A与C的交集必须>= ...
- CSU 1616: Heaps(区间DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1616 1616: Heaps Time Limit: 2 Sec Memory Lim ...
- PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)
最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...
- Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】
原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
随机推荐
- 用原生JS实现getElementsByClass
直接用jQuery里Sizzle选择器那一段源码也行,自己写了一个 function getByClass(oParent,sClass){ var aEle = oParent.getElement ...
- Swift动态添加UIImageView并添加事件
Swift动态添加UIImageView并添加事件: 1. 创建UIImageView实例,并进行初始化 2. 设置UIImageView的用户交互属性userInteractionEnabled为T ...
- SQL Server 数据库备份失败解决方法
问题:System.Data.SqlClient.SqlError: 无法使用备份文件 'D:\20160512.bak',因为原先格式化该文件时所用扇区大小为 512,而目前所在设备的扇区大小为 4 ...
- 使用TS+Sequelize实现更简洁的CRUD
如果是经常使用Node来做服务端开发的童鞋,肯定不可避免的会操作数据库,做一些增删改查(CRUD,Create Read Update Delete)的操作,如果是一些简单的操作,类似定时脚本什么的, ...
- 编写高效的JavaScript程序
作者: Addy Osmani 来源: CSDN 发布时间: 2013-01-10 14:15 阅读: 7952 次 推荐: 15 原文链接 [收藏] 英文原文:Writing Fas ...
- CentOS时区GMT修改为CST
GMT:格林尼标准时间 北京时间=GMT时间+8小时 [root@sa~]# date -R 查看目前服务器的时间标准 [root@sa~]# vi /etc/sysconfig/clock 将ZON ...
- 移动端测试=== adb 无线连接手机
无线连接(需要借助 USB 线) 除了可以通过 USB 连接设备与电脑来使用 adb,也可以通过无线连接——虽然连接过程中也有需要使用 USB 的步骤,但是连接成功之后你的设备就可以在一定范围内摆脱 ...
- JBoss6.1.0修改启动jvm内存以及修改日志级别【转】
转自 JBoss6.1.0修改启动jvm内存以及修改日志级别 - liangbinny的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/liangbinny/arti ...
- 【转】GridView 加载空行并点击编辑每一个单元格
代码 <script runat="server"> protectedvoid Button1_Click(object sender, System.EventAr ...
- sicily 1459. The Dragon of Loowater
Time Limit: 1sec Memory Limit:32MB Description Once upon a time, in the Kingdom of Loowa ...