题目大意:

找到所有的可组成连续字符串相连的位置,和循环字符串的个数

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <cmath>
#include <cstdlib> using namespace std; #define ll long long
#define N 1000100
char s[N] , b[N];
int _next[N] , len1 , len2; void get_next(int n)
{
_next[] = _next[] = ;
for(int i= ; i<n ; i++){
int j = _next[i];
while(j&&b[i]!=b[j]) j=_next[j];
if(b[i]==b[j]) _next[i+] = j+;
else _next[i+] = ;
}
} int kmp(int n)
{
int ret = ;
int i , j=;
for(i= ; i<n ; i++){
if(s[i]==b[j]) j++;
else{
while(j&&s[i]!=b[j]) j=_next[j];
if(!j && s[i]!=b[j]) j=;
else j++;
}
if(j==len2) ret++ , j=;
}
return ret;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in" , "r" , stdin);
#endif
while(scanf("%s" , s) , s[]!='#')
{
scanf("%s" , b);
len1 = strlen(s) , len2 = strlen(b);
get_next(len2);
printf("%d\n" , kmp(len1));
}
return ;
}

HDU 1358 简单kmp的更多相关文章

  1. HDU 1358 Period KMP

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1358 求周期问题,简单KMP—— AC代码: #include <iostream> # ...

  2. HDU 1358 Period(KMP计算周期)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一串字符串,判断字符串的前缀是否由某些字符串多次重复而构成. 也就是,从第1个字母 ...

  3. Hdu 1358 Period (KMP 求最小循环节)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目描述: 给出一个字符串S,输出S的前缀能表达成Ak的所有情况,每种情况输出前缀的结束位置和 ...

  4. hdu 1358 period KMP入门

    Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输 ...

  5. [HDU 1358]Period[kmp求周期]

    题意: 每一个power前缀的周期数(>1). 思路: kmp的next. 每一个前缀都询问一遍. #include <cstring> #include <cstdio> ...

  6. hdu 1358 Period(KMP入门题)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 1358 Period(KMP next数组运用)

    Period Problem Description For each prefix of a given string S with N characters (each character has ...

  8. HDU 2594 (简单KMP) Simpsons’ Hidden Talents

    题意: 有两个字符串,找一个最长子串是的该串既是第一个字的前缀,又是第二个串的后缀. 分析: 把两个串并起来然后在中间加一个无关字符,求next数组即可. #include <cstdio> ...

  9. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

随机推荐

  1. [css] 【转载】 精简高效的CSS命名准则/方法

    原文链接:http://www.zhangxinxu.com/wordpress/2010/09/%E7%B2%BE%E7%AE%80%E9%AB%98%E6%95%88%E7%9A%84css%E5 ...

  2. hdu5787(数位dp)

    基础的数位dp,才发现今天才终于彻底搞懂了数位dp... // // main.cpp // hdu5787.1 // // Created by New_Life on 16/8/10. // Co ...

  3. css编码规范

    css编码规范 https://segmentfault.com/a/1190000002460968 常用样式测试工具 W3C CSS validator:http://jigsaw.w3.org/ ...

  4. xcode 脚本编译,打包ipa

    1.清理工程 /usr/bin/xcodebuild -target targetName clean 2.编译 /usr/bin/xcodebuild -target targetName buil ...

  5. phalcon: acl权限控制

    目录控制: public/index.php: $di['aclResource']=function(){ return include_once '../app/config/frontbackA ...

  6. 十问 Linux 虚拟内存管理 (glibc) (二)

    版权声明:本文由陈福荣原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/184 来源:腾云阁 https://www.qclo ...

  7. dedecms5.7怎么取消邮箱验证以及dedecms 会员发布的文章不需要审核的解决方法

    后台 ——系统基本参数——会员设置——会员权限开通状态——改为0 1.实现会员发布文章不需要审核,非会员发布需要审核 在member这个文件夹下找到archives_sg_add.php这个文件,打开 ...

  8. 如何组织较大项目的MVC文件夹结构

    现在还用不到,拷贝下来备用,原文链接 2016 年 9 月 第 31 卷,第 9 期 ASP.NET Core - ASP.NET Core MVC 的功能切分 作者 Steve Smith | 20 ...

  9. 在centos6.5中安装mysql5.7

    简介 博主最近在研究mysql的读写分离和主从复制,一台master和两台slave,三台机器在同一个局域网中,首先就就要在centos6.5中安装mysql5.7.好了,废话不多说,接下来进入正题. ...

  10. bfs 胜利大逃亡

    http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目: Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一 ...