题目大意

给你一个串

对于一个子串如果它既是前缀又是后缀

输出它的长度以及它在原串中一共出现了多少次

分析

对于既是前缀又是后缀的判断和126B相同

然后我们只需要记录每个不同的z[i]出现了多少次

然后对于每个合法z[i]输出所有大于z[i]的数的出现次数即可

因为如果长度为z[i]的前缀是最长前缀

那么小于z[i]的前缀一定合法

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
char s[];
int n,z[],sum[],cnt,ans[];
inline void get_z(){
int i,j,k,l=,r=;
for(i=;i<n;i++){
if(i<=r)z[i]=min(r-i+,z[i-l]);
while(i+z[i]<n&&s[z[i]]==s[z[i]+i])z[i]++;
if(i+z[i]->r)r=i+z[i]-,l=i;
}
}
int main(){
int i,j,k;
scanf("%s",s);
n=strlen(s);
get_z();
for(i=;i<n;i++){
sum[z[i]]++;
if(z[i]==n-i)ans[++cnt]=z[i];
}
printf("%d\n",cnt+);
sort(ans+,ans+cnt+);
for(i=n-;i>;i--)sum[i]+=sum[i+];
for(i=;i<=cnt;i++)printf("%d %d\n",ans[i],sum[ans[i]]+);
printf("%d %d\n",n,);
return ;
}

432D Prefixes and Suffixes的更多相关文章

  1. Codeforces 432D Prefixes and Suffixes(KMP+dp)

    题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...

  2. Codeforces 432D Prefixes and Suffixes kmp

    手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit ...

  3. codeforces 432D Prefixes and Suffixes

    由于包含了前缀与后缀,很容易想到用KMP去算前缀与后缀的公共缀.另外要计算某个后缀在整个串中出现的次数,由于后缀自动机是比较容易求的,然后就直接上后缀自动机了.先分别用KMP算法与后缀自动机跑一遍,然 ...

  4. codeforces - 432D Prefixes and Suffixes (next数组)

    http://codeforces.com/problemset/problem/432/D 转自:https://blog.csdn.net/tc_to_top/article/details/38 ...

  5. Codeforces 432D Prefixes and Suffixes:KMP + dp

    题目链接:http://codeforces.com/problemset/problem/432/D 题意: 给你一个字符串s,让你找出所有既是前缀又是后缀的子串,并输出它们分别出现了多少次. 题解 ...

  6. Codeforces 432D Prefixes and Suffixes (KMP、后缀数组)

    题目链接: https://codeforces.com/contest/432/problem/D 题解: 做法一: KMP 显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大 ...

  7. codeforces432D Prefixes and Suffixes(kmp+dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Prefixes and Suffixes You have a strin ...

  8. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)

    D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Codeforces 432 D. Prefixes and Suffixes

    用扩展KMP做简单省力..... D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 meg ...

随机推荐

  1. 绕过安全狗Apache4.0版本

    参数拦截:script.空格and空格.空格or空格.union select.user() 绕过: and.order by绕过:  内联注释 union select绕过: union%23%0a ...

  2. Node.js实战14:一个简单的TCP服务器。

    本文,将会展示如何用Nodejs内置的net模块开发一个TCP服务器,同时模拟一个客户端,并实现客户端和服务端交互. net模块是nodejs内置的基础网络模块,通过使用net,可以创建一个简单的tc ...

  3. C++ 14 新特性总结

    转载自: http://www.codeceo.com/article/cpp-14-new-features.html C++14 这一继C++11 之后的新的 C++ 标准已经被正式批准,正在向 ...

  4. SpringBoot官方文档学习(二)使用Spring Boot构建系统

    强烈建议您选择一个支持依赖关系管理并且可以使用发布到“ Maven Central”仓库的构建系统.我们建议您选择Maven或Gradle.其他构建系统(例如,Ant)也可以和Spring Boot一 ...

  5. PTA第二题

    #include<string.h> #include<stdio.h> #include<malloc.h> ]; ][]={"ling",& ...

  6. 二分查找---有序数组的 Single Element

    有序数组的 Single Element 540. Single Element in a Sorted Array (Medium) Input: [1, 1, 2, 3, 3, 4, 4, 8, ...

  7. [ASP.NET Core 3框架揭秘] 依赖注入:依赖注入模式

    原文:[ASP.NET Core 3框架揭秘] 依赖注入:依赖注入模式 IoC主要体现了这样一种设计思想:通过将一组通用流程的控制权从应用转移到框架之中以实现对流程的复用,并按照“好莱坞法则”实现应用 ...

  8. 加密模块hashlib

    #coding=utf-8 import ConfigParser #配置文件模块 import hashlib #用于加密的模块 m = hashlib.md5() m.update(b'hello ...

  9. 如何将datetimepicker默认设置为空?

    在Load中,初始化 this.dateTimePicker1.Format=DateTimePickerFormat.Custom; his.dateTimePicker1.CustomFormat ...

  10. 处理键盘事件 禁止后退键(Backspace)密码或单行、多行文本框除外

    //处理键盘事件 禁止后退键(Backspace)密码或单行.多行文本框除外 function forbidBackSpace(e) { var ev = e || window.event; //获 ...