poj2752:http://poj.org/problem?id=2752

题意:给你一个串,让你求前n个字符和后n个字符相同的n有多少,从小到大输出来。

题解:这一题要深刻理解KMP的next数组,只有深刻理解,才能觉得比较轻松。推荐一个人的博客,这个人讲的比较好。

http://blog.csdn.net/zhang20072844/article/details/5779452

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=+;
int f[N],num[N],top;
char s[N];
int main(){
while(~scanf("%s",s)){
f[]=f[]=;top=;
int len=strlen(s);
for(int i=;i<len;i++){
int j=f[i];
while(j&&s[j]!=s[i])j=f[j];
f[i+]=(s[j]==s[i]?j+:);
}
int j=f[len];
num[++top]=len;
while(j!=){
num[++top]=j;
j=f[j];
}
for(int i=top;i>=;i--){
if(i==top)printf("%d",num[i]);
else
printf(" %d",num[i]);
}
printf("\n");
}
}

Seek the Name, Seek the Fame的更多相关文章

  1. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  2. poj-------------(2752)Seek the Name, Seek the Fame(kmp)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11831   Ac ...

  3. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

  4. Seek the Name, Seek the Fame(Kmp)

    Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (J ...

  5. poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Ac ...

  6. poj2752 Seek the Name, Seek the Fame(next数组的运用)

    题目链接:id=2752" style="color:rgb(202,0,0); text-decoration:none; font-family:Arial; font-siz ...

  7. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

    Seek the Name, Seek the Fame Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 24000 ...

  8. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

  9. POJ 2751:Seek the Name, Seek the Fame(Hash)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24077   Ac ...

  10. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

随机推荐

  1. ionic之应用首次启动引导页

    用户首次启动app先进入引导页,localstroge记录状态,下次启动应用不再显示引导页. HTML: <html> <head> <meta charset=&quo ...

  2. 遭遇多线程bug (1)

    某些用户,机器重启后,到第三方服务器的连接起不来,而到我们自己服务器的连接就没事. 如果连接由于网络或其他原因fail掉,过一定时间后应该会重新尝试建立连接的. 测试组做初步调查,他们能在本地环境复现 ...

  3. Qt 学习之路:QFileSystemModel

    上一章我们详细了解了QStringListModel.本章我们将再来介绍另外一个内置模型:QFileSystemModel.看起来,QFileSystemModel比QStringListModel要 ...

  4. Linux如何关闭防火墙和查看防火墙的具体情况

    1.Linux下关闭和开启防火墙 1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: ser ...

  5. service redis does not support chkconfig的解决办法

    原文链接: http://my.oschina.net/maczhao/blog/322931 问题解决办法如下: 必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中: # ch ...

  6. javascript 实用函数

    1.去除字符串空格 /*去左空格*/ function ltrim(s) { return s.replace(/^(\s*| *)/, ""); } /*去右空格*/ funct ...

  7. vertical-align各属性对比

    测试用代码 <!DOCTYPE html> <html> <head> <style> #dd { //line-height: 300px; back ...

  8. JavaScript实现弹框

    提起JS弹框,我首先想到的是Alert,然后想到的还是Alert,最后我竟然就只知道Alert.然后面试就死在这个Alert上了.恼火. 根据网上各位大神的总结,我整理了一下,也顺便学习了一下. 一. ...

  9. c# 网站发布

    .net 网站发布简单步骤: 1.选择需要发布的网站,右击->发布 1)配置文件:可以任意新建文件配置名 2)连接: 发布方法选择系统文件:选择目标位置,任意新建一个位置即可. 3)设置:选择D ...

  10. iOS9 中的一些适配问题

    1.URL scheme白名单:在info文件中加入LSApplicationQueriesSchemes(Array),添加需要的scheme,如微信:weixin.wechat 支付宝:alipa ...