Seek the Name, Seek the Fame
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Seek the Name, Seek the Fame(Kmp)
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (J ...
- 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 ...
- poj2752 Seek the Name, Seek the Fame(next数组的运用)
题目链接:id=2752" style="color:rgb(202,0,0); text-decoration:none; font-family:Arial; font-siz ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- 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 ...
- (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 ...
随机推荐
- Python中 os._exit() sys.exit() exit()区别
Python退出程序的方式有两种:os._exit(), sys.exit() 1)os._exit() 直接退出 Python程序,其后的代码也不会继续执行. 2)sys.exit() 引发一个 S ...
- 数据挖掘方面重要会议的最佳paper集合
数据挖掘方面重要会议的最佳paper集合,兴许将陆续分析一下内容: 主要有KDD.SIGMOD.VLDB.ICML.SIGIR KDD (Data Mining) 2013 Simple and De ...
- java.util.jar.JarFile cause native heap memory leak
最近项目中使用了JarFile 这个类 来load jar包中的 configuration,大致的情况如下 public void processJarEntries(JarFile paramJa ...
- 开发环境下jboss 7.1.1 Final 的jsp热部署解决方案--转
公司的网站系统使用的中间是jboss7.1.1 Final,由于有些数据和服务测试环境不具备,免不了要在测试环境调试些jsp页面,发现从jboss社区里下载的jboss应用有个问题,新增jsp页面会实 ...
- Swift: 基本操作符
这里只讲一下Swift中比较特殊的操作符,在其他语言中也存在操作符就不再讲了 Nil-Coalescing Operator: ?? The nil-coalescing operator (a ?? ...
- jquery ajax 提交表单(file && input)
用到的插件 jquery.js jquery.form.js[http://malsup.github.io/jquery.form.js] 提交页面 <form enctype="m ...
- java.util 中的property
学习中 两个博客: http://swiftlet.net/archives/1023 http://www.cnblogs.com/lingiu/p/3468464.html
- Win10中英文的切换
在UAP中,涉及到中英文版本切换,在string目录下面添加资源str 读取的时候 new Windows.ApplicationModel.Resources.ResourceLoader().Ge ...
- nodejs抓取网页内容
function loadPage(url) { var http = require('http'); var pm = new Promise(function (resolve, reject) ...
- jquery的ajax方法:ajaxStart()和ajaxStop()
ajaxStart()方法: 当AJAX请求开始时,显示加载中的提示. $("#divMessage").ajaxStart(function(){ $(this).show(); ...