Seek the Name, Seek the Fame

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 24077   Accepted: 12558

Description

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm: 

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

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above. 

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab
aaaaa

Sample Output

2 4 9 18
1 2 3 4 5

题意

给出一个字符串ch,求出ch中存在多少子串,使得这些子串既是ch的前缀,又是ch的后缀。从小到大依次输出这些子串的长度。

思路

这个题好像很多都是用KMP写的,百度看了看代码,递归的那个过程不是太理解,就用Hash写了,感觉Hash的思路更简单

记得要提前预处理一下

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
const int base=2333;
using namespace std;
char ch[maxn];
ull a[maxn];
ull b[maxn];
int vis[maxn];
int main(int argc, char const *argv[])
{
a[0]=1;
for(int i=1;i<maxn;i++)
a[i]=a[i-1]*base;
while(cin>>(ch+1))
{
ms(b);
int l=strlen(ch+1);
b[1]=ch[1];
for(int i=2;i<=l;i++)
b[i]=b[i-1]+a[i-1]*ch[i];
int k=0;
for(int i=1;i<=l;i++)
{
if(b[i]*a[l-i]==(b[l]-b[l-i]))
vis[k++]=i;
}
for(int i=0;i<k;i++)
{
if(i)
cout<<" ";
cout<<vis[i];
}
cout<<endl;
}
return 0;
}

POJ 2751:Seek the Name, Seek the Fame(Hash)的更多相关文章

  1. 总结:Mac前端开发环境的搭建(配置)

    新年新气象,在2016年的第一天,我入手了人生中第一台自己的电脑(大一时好友赠送的电脑在一次无意中烧坏了主板,此后便不断借用别人的或者网站的).macbook air,身上已无分文...接下来半年的房 ...

  2. iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView

    iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView 时间:2016-01-19 19:13:43      阅读:630      评论:0      收藏:0   ...

  3. jQuery:详解jQuery中的事件(二)

    上一篇讲到jQuery中的事件,深入学习了加载DOM和事件绑定的相关知识,这篇主要深入讨论jQuery事件中的合成事件.事件冒泡和事件移除等内容. 接上篇jQuery:详解jQuery中的事件(一) ...

  4. GJM :用JIRA管理你的项目(三)基于LDAP用户管理 [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

  5. GJM :用JIRA管理你的项目(二)JIRA语言包支持及插件支持 [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

  6. Waves:类Material Design 的圆形波浪(涟漪)点击特效插件

    Waves:类Material Design 的圆形波浪(涟漪)点击特效插件 2014/08/06 分类:前端开发, 素材分享 浏览:6,734次  来源:原创 1个评论       6,734   ...

  7. [你必须知道的.NET] 第八回:品味类型---值类型与引用类型(上)-内存有理

    原文地址:http://kb.cnblogs.com/page/42318/ 系列文章导航: [你必须知道的.NET] 开篇有益 [你必须知道的.NET] 第一回:恩怨情仇:is和as [你必须知道的 ...

  8. Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三)

     Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三) 在附录文章4,5的基础上改造MainActivity.java和MyJob.ja ...

  9. Android Priority Job Queue (Job Manager):线程任务的容错重启机制(二)

     Android Priority Job Queue (Job Manager):线程任务的容错重启机制(二) 附录文章4简单介绍了如何启动一个后台线程任务,Android Priority J ...

随机推荐

  1. JSP开发Web应用系统

    1.动态网站开发基础 1-1:动态网页 a.为什么需要动态网页(当我们需要修改网页内容的时候,都要重新上传一次覆盖原来的页面.而且,制作必须要通过专用的网页制作工具,比如:Dreamweaver.Fr ...

  2. Ubuntu中的在文件中查找和替换命令

    分类: 9.Linux技巧2009-09-29 13:40 1429人阅读 评论(0) 收藏 举报 ubuntujdbc 1.查找 find /home/guo/bin -name /*.txt | ...

  3. WINDOWS 端口查看

    查看Windows下所有使用的端口 netstat -ano 查看Windows下某一个特定的端口 netstat -ano | find "8080"   查看windows下所 ...

  4. 《Python》网络编程之验证客户端连接的合法性、socketserver模块

    一.socket的更多方法介绍 # 服务端套接字函数 s.bind() # 绑定(主机,端口号)到套接字 s.listen() # 开始TCP监听 s.accept() # 被动接受TCP客户的连接, ...

  5. Alpha 冲刺 (6/10

    Alpha 冲刺 (6/10) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务: 文字/口头描述: 1.组织会议 2.帮助队员解决 ...

  6. 总结小bug

    1.下拉刷新问题 //不要用scroll-view 他会阻止刷新 //改用view <template name="movieGridTemplate"> <!- ...

  7. 从R-CNN到FAST-RCNN再到Faster R-CNN

    (Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks)   R-CNN: (1)输入测试图像: ...

  8. 学习net core的一些疑问?

    所有的内容是否一定都要依赖注入? 获取配置文件的方式是否在类库是获取不到环境变量的? 老出现:InvalidOperationException: Unable to resolve service ...

  9. Xilinx FPGA复位逻辑处理小结(转)

    Xilinx FPGA复位逻辑处理小结 1. 为什么要复位呢? (1)FPGA上电的时候对设计进行初始化: (2)使用一个外部管脚来实现全局复位,复位作为一个同步信号将所有存储单元设置为一个已知的状态 ...

  10. 解决NPM无法安装任何包的解决方案(npm ERR! code MODULE_NOT_FOUND)

    前言 今天突然发现npm无法使用了,执行任何命令都报如下错误: npm ERR! code MODULE_NOT_FOUND npm ERR! Cannot find module 'internal ...