Seek the Name, Seek the Fame---poj2752(kmp中的Next数组)
题目链接:http://poj.org/problem?id=2752
题意就是求出是已知s串的前缀的长度x,并且要求此前缀也是s串的后缀;求出所有的 x ;
Next【i】的含义是前i个元素的前缀和后缀的最大匹配;
所以本题就很简单了。。。
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; const int N = *1e5+; char s[N];
int Next[N], n, a[N]; void GetNext()
{
int i=, j=-;
Next[] = -;
while(i<n)
{
if(j==- || s[i] == s[j])
Next[++i] = ++j;
else
j=Next[j];
}
}
int main()
{
int i;
while(scanf("%s", s)!=EOF)
{
n = strlen (s);
GetNext();
a[] = n;
i=;
while(Next[a[i-]]!=)
{
a[i] = Next[a[i-]];
i++;
}
sort(a, a+i);
for(int j=; j<i; j++)
printf("%d%c", a[j], i-==j?'\n':' ');
}
return ;
}
Seek the Name, Seek the Fame---poj2752(kmp中的Next数组)的更多相关文章
- POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解
题意: 要求你给出每个前后缀相同的串的长度,比如: "alala"的前缀分别为{"a", "al", "ala", &q ...
- 深入理解kmp中的next数组
next数组 1. 如果对于值k,已有p0 p1, ..., pk-1 = pj-k pj-k+1, ..., pj-1,相当于next[j] = k. 此意味着什么呢?究其本质,next[j] = ...
- 关于KMP中求next数组的思考【转】
文章转自 http://www.tuicool.com/articles/yayeIbe.这是我看到关于求next数组,解释最好的一篇文章!!!!!!! KMP的next数组求法是很不容易搞清楚的一部 ...
- POJ2752 Seek the Name, Seek the Fame —— KMP next数组
题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Li ...
- 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 ...
- POJ2752 Seek the Name, Seek the Fame 【KMP】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11602 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 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
随机推荐
- vim 笔记
1.替换 :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vivian/sky/g 替换当前行所有 vivian 为 sky :%s/vivian/sky/(等同于 : ...
- 使用tcpdump观察IPV4头部结构
sudo tcpdump -nt -i lo #抓取本地回路上的数据包 先运行上面的命令,然后再另一个终端运行下图所示的命令: [root@linux 5]# sudo tcpdump -nt -i ...
- maven配置nexus
setting配置: <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the ...
- "crsctl check crs" command hangs at EVMD check
Pre-11gR2: "crsctl check crs" command hangs at EVMD check (文档 ID 1578875.1) APPLIES TO: ...
- web automation 常用技术比较
selenium2支持通过各种driver(FirfoxDriver,IternetExplorerDriver,OperaDriver,ChromeDriver)驱动真实浏览器完成测试. 除此之外, ...
- MySQL 5.6的72个新特性(译)
一,安全提高 1.提供保存加密认证信息的方法,使用.mylogin.cnf文件.使用 mysql_config_editor可以创建此文件.这个文件可以进行连接数据库的访问授权. mysql_conf ...
- 你有自己的Web缓存知识体系吗?
赵舜东 江湖人称赵班长,曾在武警某部负责指挥自动化的架构和运维工作,2008年退役后一直从事互联网运维工作.曾带团队负责国内某电商的运维工作,<saltstack入门与实践>作者,某学院高 ...
- css中!important的用法总结
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- pydoc介绍
Ka-Ping Yee 曾创建了一个相当著名的模块,名叫 pydoc (比较而言: pydoc 可以做到 perldoc 所能做的任何事,并且做得更好.更漂亮:-).对于 Python 2.1 来说, ...
- Mac OSX使用 XAMPP path 下的php
修改-/.bash_profile文件或.zshrc文件 export XAMPP_HOME=/Applications/XAMPP export PATH=${XAMPP_HOME}/bin:${P ...