BZOJ1355:[Baltic2009]Radio Transmission
浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html
题目传送门:https://lydsy.com/JudgeOnline/problem.php?id=1355
跟POJ1961类似,答案就是\(n-nxt_n\)
时间复杂度:\(O(n)\)
空间复杂度:\(O(n)\)
代码如下:
#include <cstdio>
using namespace std;
const int maxn=1e6+5;
int n;
char s[maxn];
int nxt[maxn];
int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
void make_nxt() {
for(int j=0,i=2;i<=n;i++) {
while(j&&s[j+1]!=s[i])j=nxt[j];
if(s[j+1]==s[i])j++;nxt[i]=j;
}
}
int main() {
n=read();
scanf("%s",s+1);
make_nxt();
printf("%d\n",n-nxt[n]);
return 0;
}
BZOJ1355:[Baltic2009]Radio Transmission的更多相关文章
- bzoj1355: [Baltic2009]Radio Transmission
将原串看成是循环节的后缀加上若干个循环节,那么考虑每种情况都会发现n-next[n]就是最小循环节.(一开始总输出n...然后发现build_next连调用都没有,%%% #include<cs ...
- 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 ...
- [Baltic2009]Radio Transmission
bzoj 1355: [Baltic2009]Radio Transmission http://www.lydsy.com/JudgeOnline/problem.php?id=1355 Time ...
- 1355: [Baltic2009]Radio Transmission[循环节]
1355: [Baltic2009]Radio Transmission Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 796 Solved: 538 ...
- 【kmp算法】bzoj1355 [Baltic2009]Radio Transmission
引用题解:http://blog.csdn.net/wyfcyx_forever/article/details/40347425 #include<cstdio> #include< ...
- [KMP][BZOJ1355][Baltic2009]Radio Transmission
题面 Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,\(1 < L ...
- BZOJ1355: [Baltic2009]Radio Transmission KMP
Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...
- BZOJ 1355 Baltic2009 Radio Transmission KMP算法
标题效果:给定一个字符串,求最小周期节(不能整除) 示例Hint这是错误的忽略了就好了 环路部分应该是cab 这个称号充分利用KMP在next自然阵列,那是,n-next[n]它表示一个循环节 POJ ...
随机推荐
- COS-2OS结构和硬件支持
操作系统(Operating System,简称OS),是电子计算机系统中负责支撑应用程序运行环境以及用户操作环境的系统软件,同时也是计算机系统的核心与基石.它的职责常包括对硬件的直接监管.对各种计算 ...
- 使用shiro缓存用户身份信息的时候报:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
最近在使用shiro缓存用户的身份信息的时候,报了simpleByteSource不能序列化,跟进源码一看,原来这个类没有实现序列化的接口,但是我在缓存身份信息的实现又要用到这个类,解决方法:重写一个 ...
- mysql分库分表(一)
mysql分库分表 参考: https://blog.csdn.net/xlgen157387/article/details/53976153 https://blog.csdn.net/cleve ...
- numpy数组各种乘法
In [34]: a Out[34]: array([[1, 4], [5, 6]]) In [35]: b Out[35]: array([[4, 1], [2, 2]]) In [36]: np. ...
- HDFS集群启动的常见问题
hdfs集群启动的常见问题 1.用浏览器访问namenode的50070端口,不正常,需要诊断问题出在哪里: a.在服务器的终端命令行使用jps查看相关进程 观察节点是否存活 b.如果已经知道了启动失 ...
- hermite插值
Hermite 插值就是要求插值函数不仅经过所给节点,而且要保证在该点的导数也相等.<备注:虽然还不理解这句话,但是还是先放这里!> 所谓样条曲线(Spline Curves)是指给定一组 ...
- mongodb停止遇到shutdownServer failed: unauthorized: this command must run from localhost when running db without auth解决方法
停止mongodb use admin db.shutdownServer(); mongos> db.shutdownServer(); assert failed : unexpected ...
- 【lightoj-1026】Critical Links(桥)
题意: 给出无向图,求桥的模板题. #include <bits/stdc++.h> using namespace std; ; int dfn[N], low[N];//时间戳;low ...
- LeetCode OJ :Remove Linked List Elements (移除链表元素)
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- Integer类分析(jdk8)
一.构造函数 1. Integer类继承Number类,实现Comparable接口,重写了compareTo()方法. 2. Integer最小值为-2147483648,最大值为214748364 ...