Problem Description
随着人们年龄的增长更大,更聪明还是越大越愚蠢,这是一个值,相同的问题Eddy也一直在思考,由于他在非常小的时候就知道亲和串怎样推断了,可是发现,如今长大了却不知道怎么去推断亲和串了,于是他仅仅好又再一次来请教聪明且乐于助人的你来解决问题。

亲和串的定义是这种:给定两个字符串s1和s2,假设能通过s1循环移位。使s2包括在s1中,那么我们就说s2 是s1的亲和串。
 
Input
本题有多组測试数据。每组数据的第一行包括输入字符串s1,第二行包括输入字符串s2,s1与s2的长度均小于100000。

 
Output
假设s2是s1的亲和串,则输出"yes"。反之。输出"no"。每组測试的输出占一行。
 
Sample Input
AABCD
CDAA
ASD
ASDF
 
Sample Output
yes
no
 
Author
Eddy
 

就是把第一个串加倍后能不能包括第一个串

kmp模板

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
using namespace std;
#define N 200005 char a[N],b[N];
int next[N]; void getfail(char *b)
{
int i,j;
i=0,j=-1;
next[0]=-1; int len=strlen(b);
while(i<len)
{
if(j==-1||b[i]==b[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
} int kmp(char *a,char *b)
{
int i,j;
int lena=strlen(a);
int lenb=strlen(b);
i=j=0;
while(i<lena)
{
if(j==-1||a[i]==b[j])
{
i++;
j++;
}
else
j=next[j]; if(j==lenb)
return 1;
}
return 0;
}
int main()
{
int i,j;
while(~scanf("%s%s",a,b))
{
int len=strlen(a);
for(i=0;i<len;i++)
a[len+i]=a[i];
a[i+len]='\0'; getfail(b); if(kmp(a,b))
printf("yes\n");
else
printf("no\n");
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

HDU 2203 亲串(kmp)的更多相关文章

  1. HDU 2203 亲和串(KMP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2203 题目: 亲和串 Time Limit: 3000/1000 MS (Java/Others)   ...

  2. hdu 2203亲和串 (kmp)

    #include<cstdio>#include<iostream>#include<cstring>#include<string>using nam ...

  3. hdu 2203:亲和串(水题,串的练习)

    亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. hdu 2203 亲和串

    把T串扩展成两倍   然后KMP  注意T的长度要大于P的长度 #include <iostream> #include <cstdio> #include <cstri ...

  5. HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

    Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现 ...

  6. 亲串 (hdu 2203 KMP)

    亲串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. HDU 2203 kmp

    http://acm.hdu.edu.cn/showproblem.php?pid=2203 亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  8. HDOJ 2203 亲和串 【KMP】

    HDOJ 2203 亲和串 [KMP] Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  9. HUD 2203 亲和串

    HUD 2203 亲和串 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 - ...

随机推荐

  1. Android网络服务发现(NSD)协议的使用

    Android的网络服务发现协议(NSD)能够用于在小范围的网络中发现邻近设备上的某个应用.这对于一些社交网络.多人游戏类的应用会很有帮助. Android的NSD的用法大致上分为四种操作: 1. 注 ...

  2. winfrom 倒计时控件

    最近在做一个快递柜项目,要求在用户没有操作的时间到了一分钟,自动返回主页,我于是封装了一个倒计时控件,废话少说,直接上代码 public partial class RemainingTimeUC : ...

  3. 外网SSH访问内网LINUX的N种方法

    外网SSH访问内网LINUX的N种方法 http://www.nat123.com/Pages_8_260.jsp 一,动态公网IP环境 1,环境描述: 路由器分配的是动态公网IP,且有路由管理权限, ...

  4. HUNNU11354:Is the Name of This Problem

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11354&courseid=0 Problem des ...

  5. Welcome Docker to SUSE Linux Enterprise Server【水平有限,中英对比,求纠错】

      原文:Welcome Docker to SUSE Linux Enterprise Server Lightweight virtualization is a hot topic these ...

  6. Oracle SQL Lesson (5) - 使用组函数输出聚合数据

    组函数AVGCOUNTMAXMINSUMVARIANCE:方差STDDEV:标准差 SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary)F ...

  7. Python编程预约参观北京行动纲要

    通过Python程序来模拟一个统一平台预约参观北京,包含验证码识别.登陆.据医院.时间.有关主管部门号等查询. 此程序仅供学习使用,请勿用于其他用途. 1.验证码图片 def getCodePic() ...

  8. 一起学习android图片四舍五入图片集资源 (28)

    效果图: 參看下面代码: public class MainActivity extends Activity { private ImageView imageView1; private Imag ...

  9. Codeforces554D:Kyoya and Permutation

    Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct ...

  10. 三白话经典算法系列 Shell排序实现

    山是包插入的精髓排序排序,这种方法,也被称为窄增量排序.因为DL.Shell至1959提出命名. 该方法的基本思想是:先将整个待排元素序列切割成若干个子序列(由相隔某个"增量"的元 ...