【BZOJ】1355 [Baltic2009]Radio Transmission
【算法】KMP
【题解】KMP中n-next[n]得到最小循环节的性质。
考虑一个循环串(最后一个循环节可能残缺),它最长的【后缀=前缀】一定是以第二个循环节为起始位置的后缀。
正着考虑的话假设后缀T以x+1开始,S为前缀那:
1.S(1~x)=T(1~x)即S(x+1~2x)
2.S(x+1~2x)=T(x+1~2x)即S(2x+1~3x)。
这样叠加到最后就是循环串了。
注意:
1.当fail[n]=0的时候,循环节默认为自身要判否。
2.n/(n-fail[n])表示循环次数,不能整除说明循环节残缺。
#include<cstdio>
const int maxn=;
char s[maxn];
int n,p[maxn];
int main()
{
scanf("%d%s",&n,s+);
int j=;p[]=;
for(int i=;i<=n;i++)
{
while(j>&&s[j+]!=s[i])j=p[j];
if(s[j+]==s[i])j++;
p[i]=j;
}
printf("%d",n-p[n]);
return ;
}
【BZOJ】1355 [Baltic2009]Radio Transmission的更多相关文章
- BZOJ——T 1355: [Baltic2009]Radio Transmission
http://www.lydsy.com/JudgeOnline/problem.php?id=1355 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
- BZOJ 1355: [Baltic2009]Radio Transmission( kmp )
自己YY一下可以发现answer = n - fail[ n ] ------------------------------------------------------------------ ...
- BZOJ 1355: [Baltic2009]Radio Transmission [KMP 循环节]
1355: [Baltic2009]Radio Transmission Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 792 Solved: 535 ...
- 1355: [Baltic2009]Radio Transmission[循环节]
1355: [Baltic2009]Radio Transmission Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 796 Solved: 538 ...
- bzoj 1355: [Baltic2009]Radio Transmission【kmp】
kmp复健,答案是n-next[n] #include<iostream> #include<cstdio> using namespace std; const int N= ...
- BZOJ 1355: [Baltic2009]Radio Transmission
Description 一个字符串最短周期. Sol KMP. 最短周期就是 \(n-next[n]\) 证明: 当该字符串不存在周期的时候 \(next[n]=0\) 成立. 当存在周期的时候 \( ...
- BZOJ 1355 Baltic2009 Radio Transmission KMP算法
标题效果:给定一个字符串,求最小周期节(不能整除) 示例Hint这是错误的忽略了就好了 环路部分应该是cab 这个称号充分利用KMP在next自然阵列,那是,n-next[n]它表示一个循环节 POJ ...
- 【kmp算法】bzoj1355 [Baltic2009]Radio Transmission
引用题解:http://blog.csdn.net/wyfcyx_forever/article/details/40347425 #include<cstdio> #include< ...
- BZOJ 1355: [Baltic2009]Radio Transmission AC自动机/KMP
被一个KMP傻题搞蒙圈了,此题AC自动机空间超限,只能用KMP写(我只会AC自动机QAQ)...... AC自动机 Code: // luogu-judger-enable-o2 #include & ...
随机推荐
- PAT 甲级 1040 Longest Symmetric String
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...
- HDU 2105 The Center of Gravity
http://acm.hdu.edu.cn/showproblem.php?pid=2105 Problem Description Everyone know the story that how ...
- 关于command 'gcc' failed with exit status 1 解决方法
Python踩坑之路 Setup script exited with error: command 'gcc' failed with exit status 1 由于没有正确安装Python开发环 ...
- windows操作系统下载tomcat,并与eclipse进行整合
进入Tomcat官网之后,在左边我们看到,Tomcat的有6,7,8这三个最流行的版本,我们可以点击进去下载想要的版本. 进入里面之后,可以看见有64位的和32位的,就看自己的电脑是多少位的了,如果电 ...
- vue ui components
vue ui components h_ui https://www.npmjs.com/~hs_ui https://www.npmjs.com/package/h_ui_beta https:// ...
- oracle锁与死锁概念,阻塞产生的原因以及解决方案
锁是一种机制,一直存在:死锁是一种错误,尽量避免. 首先,要理解锁和死锁的概念: 1.锁: 定义:简单的说,锁是数据库为了保证数据的一致性而存在的一种机制,其他数据库一样有,只不过实现机制上可能大 ...
- 【ASP.NET Core】ASP.NET Core 依赖注入
一.什么是依赖注入(Denpendency Injection) 这也是个老身常谈的问题,到底依赖注入是什么? 为什么要用它? 初学者特别容易对控制反转IOC(Iversion of Control) ...
- poj1958——Strange Towers of Hanoi
The teacher points to the blackboard (Fig. 4) and says: "So here is the problem: There are thre ...
- jQuery绑定事件
1.事件绑定的方式 事件 DOM:三种绑定方式 jQuery: #前面几种内部调用的全是on $('.c1').click() $('.c1').blur() $('.c1').aaaaa() $(' ...
- 【BZOJ4198】【NOI2015】荷马史诗(贪心,Huffman树)
[BZOJ4198][NOI2015]荷马史诗(贪心,Huffman树) 题面 BZOJ 洛谷 题解 合并果子都是不知道多久以前做过的了.现在才知道原来本质就是一棵哈夫曼树啊. 这题我们仔细研究一下题 ...