BZOJ 1511: [POI2006]OKR-Periods of Words
Description
求一个最长周期.
Sol
KMP.
一个点的最短周期就是 \(i-next[i]\)
此外 \(i-next[next[i]],i-next[next[next[i]]]\) 等等都是它的周期,知道第一个为0的位置.
然后就没有然后了.
Code
/**************************************************************
Problem: 1511
User: BeiYu
Language: C++
Result: Accepted
Time:140 ms
Memory:6172 kb
****************************************************************/ #include<cstdio>
#include<iostream>
using namespace std; const int N = 1000005; int n;long long ans;
char s[N];
int f[N]; int main(){
scanf("%d",&n);
scanf("%s",s+1); for(int i=2,j=0;i<=n;i++){
while(j && s[i]!=s[j+1]) j=f[j];
if(s[i]==s[j+1]) j++;
f[i]=j;
} for(int i=1;i<=n;i++)
while(f[f[i]]) f[i]=f[f[i]]; for(int i=1;i<=n;i++) if(f[i]) ans=ans+i-f[i];
cout<<ans<<endl;
return 0;
}
BZOJ 1511: [POI2006]OKR-Periods of Words的更多相关文章
- bzoj 1511: [POI2006]OKR-Periods of Words【kmp】
n-ne[n]是n的最长循环节长度,其实就是n-最短前缀=后缀长度 然后我们要求最短循环节,其实就是ne一直往前跳,跳到不能跳为止,这时的n-ne[n]就是n的最短循环节长度 #include< ...
- bzoj 1513 POI2006 Tet-Tetris 3D 二维线段树+标记永久化
1511: [POI2006]OKR-Periods of Words Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 351 Solved: 220[S ...
- 1511: [POI2006]OKR-Periods of Words
1511: [POI2006]OKR-Periods of Words https://www.lydsy.com/JudgeOnline/problem.php?id=1511 题意: 对于一个串的 ...
- 模拟 - BZOJ 1510 [POI2006] Kra-The Disks
BZOJ 1510 [POI2006] Kra-The Disks 描述 Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...
- bzoj 1513 [POI2006]Tet-Tetris 3D(二维线段树)
1513: [POI2006]Tet-Tetris 3D Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 540 Solved: 175[Submit ...
- bzoj 1510 [POI2006]Kra-The Disks 二分
1510: [POI2006]Kra-The Disks Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 466 Solved: 272[Submit][ ...
- bzoj 1520 [POI2006]Szk-Schools 费用流
[POI2006]Szk-Schools Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 743 Solved: 381[Submit][Status][ ...
- bzoj 1517 [POI2006]Met 贪心
[POI2006]Met Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 203 Solved: 108[Submit][Status][Discus ...
- BZOJ 1513 [POI2006]Tet-Tetris 3D
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1513 题意:三维空间,有一些立方体在垂直下落.立方体的左下角坐标(x,y)以及长宽 ...
随机推荐
- win7开防火墙,允许别人远程
- delphi SQL操作
create表 时不可以有类似Name之类的字段创建,否则报错,即使access数据库中执行正常 insert的字符型字段中不可以有英文单引号 ' 之类的存在,否则报错,可以用#39 代替,减少英 ...
- Mastering C# structs
http://www.developerfusion.com/article/84519/mastering-structs-in-c/
- Sphinx 2.2.6 window下安装全过程 未完 持续标记~~~~
由于在win8.1下安装 选的这个版本 Win64 binaries w/MySQL+PgSQL+libstemmer+id64 support 2.2.6-release 7.3M 下载页面 htt ...
- IP欺骗原理与过程分析
IP欺骗攻击法 原创:r00t <r00t@unsecret.org> QQ: 22664566 http://www.unsecret.org --------------------- ...
- yii2权限控制rbac之rule详细讲解(转)
在我们之前yii2搭建后台以及rbac详细教程中,不知道你曾经疑惑过没有一个问题,rule表是做什么的,为什么在整个过程中我们都没有涉及到这张表? 相信我不说,部分人也都会去尝试,或百度或google ...
- motto1
不要失去了才懂得珍惜.很多东西是不能再来的,又有很多东西再来是要付出代价的,所以,好好珍惜你现在拥有的一切,努力去争取你现在没有的.
- hdu4982 Goffi and Squary Partition (DFS解法)
BestCoder Round #6 B http://acm.hdu.edu.cn/showproblem.php?pid=4982 Goffi and Squary Partition Time ...
- C语言动态内存分配
考虑下面三段代码: 片段1 void GetMemory(char *p) { p = (); } void Test(void) { char *str = NULL; GetMemory(str) ...
- "当前方法的代码已经过优化,无法计算表达式的值"的这个错误的解决方案!!!
http://blog.useasp.net/archive/2012/09/12/how-to-debug-dotnet-framework-source-when-throw-the-code-o ...