poj3461:http://poj.org/problem?id=3461

题意:求一个串在另一个串中出现的次数。

题解:直接套用KMP即可,在统计的时候做一下修改。找到之后不是直接返回,而是移动i-(j-next[j])位。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#define N 1000005
using namespace std;
int next[N];
char s1[N],s2[N];
int len1,len2,ans;
void getnext(int plen){
int i = ,j = -;
next[] = -;
while( i<plen ){
if(j==-||s1[i]==s1[j]){
++i;++j;
if(s1[i]!=s1[j] )
next[i] = j;
else
next[i] = next[j];
}
else
j = next[j];
}
}
void KMP(){
getnext(len1);
int i = ,j = ;
while (i<len2&&j<len1){
if( j == - || s2[i] == s1[j] ){
++i;
++j;
}
else {
j = next[j]; }
if( j==len1 ){//找到一个匹配串之后,不是在原来串中往后移动一位,而是移动i-(j-next[j]);
ans++;
j=next[j];
}
}
}
int main(){
int k;
scanf("%d",&k);
while(k--){
scanf("%s%s",s1,s2);
len1=strlen(s1);
len2=strlen(s2);
ans=;
KMP();
printf("%d\n",ans);
}
}

Oulipo的更多相关文章

  1. C++之路进阶——poj3461(Oulipo)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35694   Accepted: 14424 Descript ...

  2. poj3461 Oulipo(KMP模板)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17795   Accepted: 7160 Descripti ...

  3. Match:Oulipo(POJ 3461)

     Oulipo 题目大意:给你一个字符串,要你找到字符串包含指定子串的个数 只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧 #include < ...

  4. KMP算法 hdu4686 Oulipo

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  5. hdu----1686 Oulipo (ac自动机)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  6. 字符串hash - POJ 3461 Oulipo

    Oulipo Problem's Link ---------------------------------------------------------------------------- M ...

  7. POJ 3461 Oulipo

      E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  8. Oulipo (kmp)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26857   Accepted: 10709 Descript ...

  9. POJ 3461 Oulipo(乌力波)

    POJ 3461 Oulipo(乌力波) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] The French autho ...

  10. A - Oulipo

    A - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

随机推荐

  1. Mysql binlog日志解析

    1. 摘要: Mysql日志抽取与解析正如名字所将的那样,分抽取和解析两个部分.这里Mysql日志主要是指binlog日志.二进制日志由配置文件的log-bin选项负责启用,Mysql服务器将在数据根 ...

  2. JavaBean的boolean isXXX反序列化问题

    JavaBean规范中规定boolean的getter/setter 为isXXX/setXXX,包装类Boolean的getter/setter 为getXXX/setXXX,其中XXX为变量名(I ...

  3. Android Intent传递对象小结

    效果: 想看实例的,感兴趣的能够看之前的一篇文章 Android ViewPager Fragment实现选项卡 部分关键代码: public class SerializeActivity exte ...

  4. java 服务端解决ajax跨域问题

    //过滤器方式 可以更改为拦截器方式public class SimpleCORSFilter implements Filter { public void doFilter(ServletRequ ...

  5. [CSS3] CSS :target Selector

    The :target selector allows us to interact with a fragment identifier, or hash, in our URL from CSS. ...

  6. [ES6] Array.findIndex()

    In es5, you can use indexOf to get the index of one item in an array. In es6, you can use findIndex( ...

  7. 深入懂得android view 生命周期

    作为自定义 view 的基础,如果不了解android  view 的生命周期 , 那么你将会在后期的维护中发现这样那样的问题 ....... 做过一段时间android 开发的同学都知道,一般 on ...

  8. Linux开发工具之Makefile(上)

    二.makefile(上) 01.make工具   利用make工具可以自动完成编译工作.这些工作包括:如果修改了某几 个源文件,则只重装新编译这几个源文件:如果某个头文件被修改了,则 重新编译所有包 ...

  9. JAVA集合差异

    接口 简述 实现 操作特性 成员要求 Set 成员不能重复 HashSet 外部无序地遍历成员 成员可为任意Object子类的对象,但如果覆盖了equals方法,同时注意修改hashCode方法. T ...

  10. angular.bind

    angular.bind :Returns a function which calls function fn bound to self (self becomes the this for fn ...