• CSU


    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

    思路:两遍KMP,正一遍,反着再来一遍


    #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--] = '';
    			while (t[tlen] == '0'&&tlen > 1)
    				t[tlen--] = '';
    			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
    ");
    			else
    				printf("No
    ");
    		}
    	}
    	return 0;
    }

  • 相关阅读:
    WIN10修改桌面路径到(其他盘)教程
    C#通过IMessageFilter捕获鼠标消息
    C# ICON和Image互转
    由于找不到 opencv_world320.dll,无法继续执行代
    HttpWebRequest.Connection的问题
    远程服务器环境调用本地JS启动摄像头功能遇见的问题
    nginx反向代理配置
    获取开源天气信息的API
    Java实现八种排序算法(代码详细解释)
    Java面试之前复习总结(二)
  • 原文地址:https://www.cnblogs.com/csu-lmw/p/9124460.html
Copyright © 2020-2023  润新知