poj 2752Seek the Name, Seek the Fame
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
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
______________________________________________________________________________________________________________________________________________________
题目大意:给定字符串S,求出S的所有公共前后缀的长度(包含自身)
KMP求出next[],S的公共前后缀中前缀的公共前后缀也是S的公共前后缀。用此循环即可。
_______________________________________________________________________________________________________________________________________________________
- 1 #include<cstdio>
- 2 #include<cstring>
- 3 #include<algorithm>
- 4
- 5 using namespace std;
- 6 const int maxl=400010;
- 7 char s[maxl];
- 8 int next[maxl],l;
- 9 int ans[maxl],js=0,ll;
- 10 void getnext()
- 11 {
- 12 l=strlen(s);
- 13 next[0]=-1;
- 14 for(int j,i=1;i<l;i++)
- 15 {
- 16 j=next[i-1];
- 17 while(s[i]!=s[j+1] && j>=0)j=next[j];
- 18 next[i]=s[i]==s[j+1]?j+1:-1;
- 19 }
- 20 }
- 21 int main()
- 22 {
- 23 while(~scanf("%s",s))
- 24 {
- 25 getnext();
- 26 js=0;ll=l-1;
- 27 while(next[ll]!=-1)
- 28 {
- 29 ans[js++]=next[ll];
- 30 ll=next[ll];
- 31 }
- 32 while(js>0)printf("%d ",ans[--js]+1);
- 33 printf("%d\n",l);
- 34 }
- 35 return 0;
- 36 }
poj 2752Seek the Name, Seek the Fame的更多相关文章
- POJ 2752Seek the Name, Seek the Fame(next数组妙用 + 既是前缀也是后缀)
题目链接 题意:求一个字符串中 前缀 和 后缀 相同的长度 分析: 对于一个字符串他自己的长度肯定是可以的.然后如果满足 前缀 和 后缀相等,那个前缀 最后一个字符 一定 和 该字符串最后一个字符相等 ...
- 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
传送门 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14761 Accepted: 7407 Description ...
- 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 ...
- (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 ...
- KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame
Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...
- 【POJ 2752 Seek the Name, Seek the Fame】
Time Limit: 2000MSMemory Limit: 65536K Description The little cat is so famous, that many couples tr ...
- Seek the Name, Seek the Fame POJ - 2752
Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应 ...
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
随机推荐
- Mysql Cluster7.5.6 windows10 部署安装
部署方法网上很多,以下是我的实践过程,供大家参考. 1. 硬件:3台虚拟机,全是windows 10 x64 2. 网络架构: 管理节点:192.168.37.128 数据节点 / SQL节点: 19 ...
- Spring Security OAuth2.0认证授权一:框架搭建和认证测试
一.OAuth2.0介绍 OAuth(开放授权)是一个开放标准,允许用户授权第三方应用访问他们存储在另外的服务提供者上的信息,而不 需要将用户名和密码提供给第三方应用或分享他们数据的所有内容. 1.s ...
- 伪静态 RewriteRule-htaccess
伪静态实际上是利用PHP把当前地址解析成另一种方法来访问网站,要学伪静态规则的写法,要懂一点正则 一.正则表达式教程 有一个经典的教程:正则表达式30分钟入门教程 常用正则如下: . 换行符以外的所有 ...
- Modbus 仿真测试工具 Mod_Rssim 详细图文教程
Mod_RSsim是一款轻量级的Modbus从机模拟器,它可以模拟ModBusTCP和ModBusRTU的从机,能够同时模拟254个被控站,软件使用简单方便,可以满足一般的主机调试. 官方网站:www ...
- python实现99乘法表
for x in range(1,10): for y in range(1,10): if x>=y: print("%d*%d=%d\t"%(y,x,x*y),end=' ...
- ACL技术(访问控制列表)
• Access Control List • 访问控制列表 • 是一种包过滤技术 • ACL基于IP包头的IP地址.四层TCP/UDP头部的端口号.[五层数据]进行过滤 • ...
- 配置Oracle数据库和监听随Linux系统自启动【转】
配置Oracle数据库和监听随Linux系统自启动 在某些情况下需要在Linux操作系统上提供一种无人值守的随机启动Oracle的功能,目的也许仅仅是为了帮助那些对Oracle细节非常不关心 ...
- 肌肤管家SkinRun V3S智能皮肤检测仪,用AI探索肌肤问题
继肌肤管家SkinRun V3皮肤检测仪之后,肌肤管家SkinRun近期又一重磅推出的肌肤管家SkinRun V3S 智能肌肤测试仪引起了美业人的广泛关注.据了解它汇集百万皮肤数据,利用五光谱原理和人 ...
- SpringBoot配置文件(2)
六.配置文件加载 SpringBoot 启动会扫描以下位置的application.properties或者application.yml文件作为SpringBoot的默认配置文件 file:./co ...
- RAC上的DG搭建
准备工作 修改rman_backup这个文件的所有者和所属组,修改为oracle用户的oinstall组的文件 #chown –R oracle:oinstall /rman_backup/ 主库和备 ...