poj2752Seek the Name, Seek the Fame(next数组)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 24390 | Accepted: 12723 |
Description
Step1. Connect the father's name and the mother's name, to a new string S.
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).
Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)
Input
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
Output
Sample Input
ababcababababcabab
aaaaa
Sample Output
2 4 9 18
1 2 3 4 5
Source
#include<iostream>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 400005
int next[MAX];
char s[MAX];
int len;
void get_next()
{
int i=,j=-;
next[i]=j;
for(i=;i<len;i++)
{
while(j>-&&s[j+]!=s[i])
j=next[j];
if(s[j+]==s[i]) j++;
next[i]=j;
}
}
void output(int x)
{
if(next[x]==-)
{
printf("%d ",x+);
return ;
}
output(next[x]);
printf("%d ",x+);
//cout<<"ok"<<endl;
}
int main()
{
/*ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
while(~scanf("%s",s))
{
memset(next,,sizeof(next));
len=strlen(s);
get_next();
/*for(int i=0;i<len;i++)
cout<<next[i]<<" ";
cout<<endl;*/
output(len-);
printf("\n");
}
return ;
}
poj2752Seek the Name, Seek the Fame(next数组)的更多相关文章
- poj2752seek the name, seek the fame【kmp】
The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the l ...
- poj2752Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- POJ 2752Seek the Name, Seek the Fame(next数组妙用 + 既是前缀也是后缀)
题目链接 题意:求一个字符串中 前缀 和 后缀 相同的长度 分析: 对于一个字符串他自己的长度肯定是可以的.然后如果满足 前缀 和 后缀相等,那个前缀 最后一个字符 一定 和 该字符串最后一个字符相等 ...
- POJ 2752 Seek the Name, Seek the Fame(next数组的理解)
做此题,只要理解好next数组就行....................... #include <cstdio> #include <cmath> #include < ...
- POJ--2752--Seek the Name, Seek the Fame【KMP】
链接:http://poj.org/problem? id=2752 题意:对于一个字符串S,可能存在前n个字符等于后n个字符,从小到大输出这些n值. 思路:这道题加深了对next数组的理解.next ...
- POJ 2752 Seek the Name, Seek the Fame next数组理解加深
题意:给你一个字符串,寻找前缀和后缀相同的子串(包括原串). 从小到大排列输出其子串的长度 思路:KMP next 数组应用. 其实就是一个数学推导过程. 首先由next数组 可知s(ab) = s ...
- 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 ...
- 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 ...
随机推荐
- Redis在windows下的环境搭建
Redis在windows下的环境搭建 下载windows版本redis,,官方下载地址:http://redis.io/download, 不过官方没有Windows版本,官网只提供linux版本的 ...
- 141-FMC141-4路 250Msps/16bits ADC, FMC板卡
FMC141-4路 250Msps/16bits ADC, FMC板卡 一.产品概述: 本板卡基于 FMC 标准板卡,实现 4 路 16-bit/250Msps ADC 功能.遵循 VITA 57 标 ...
- ViewMode
一.ViewMode 实现使用场景-Model枚举的情景下, 注意:枚举声明在后台的时候,需要渲染界面,页面表格使用 Bootstrap Table插件-事先通过ajax 渲染(数据库读取值1.2.3 ...
- Django学习笔记-修改Django的默认的数据库
1.修改设置settings中的配置 DATABASES = { 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os ...
- CS184.1X 计算机图形学导论(第四讲)
一.齐次变换 1.平移变换 变换矩阵不能包含X,Y,Z等坐标变量 如果x坐标向右平移了5个单位长度,则x~=x+5.在变换矩阵中表示的时候添加一个w坐标变量.通过加入一个w坐标,可以实现平移变换 1& ...
- Jenkins ant打包部署
选择项目 自由风格
- [Luogu1938][USACO09NOV]找工就业Job Hunt
原题链接:https://www.luogu.org/problem/show?pid=1938 这一道题有一个比较难的点就是,这一张图上,是点上有权.既然点上有权的话,我们就不好一下子使用最短路了. ...
- Vue 滚动条动画
<template> <div class="home-main"> <div class="progress-main"> ...
- struts2结果跳转和参数获取
一.结果跳转方式 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC ...
- Heartbeat安装及配置
1.yum源安装 yum -y install heartbeat 更新yum源 yum install epel-release -y yum源有问题,改用下载rpm包安装 2.rpm安装 下载rp ...