bzoj1355: [Baltic2009]Radio Transmission
将原串看成是循环节的后缀加上若干个循环节,那么考虑每种情况都会发现n-next[n]就是最小循环节。(一开始总输出n。。。然后发现build_next连调用都没有,%%%
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,s,t) for(int i=s;i<=t;i++)
const int nmax=1000005;
char s[nmax];
int next[nmax],len;
void build_next(){
next[0]=next[1]=0;
REP(i,1,len-1){
int t=next[i];
while(t&&s[t]!=s[i]) t=next[t];
next[i+1]= s[t]==s[i]? t+1: 0;
}
}
int main(){
scanf("%d%s",&len,s);
build_next();
printf("%d\n",len-next[len]);
return 0;
}
1355: [Baltic2009]Radio Transmission
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 694 Solved: 465
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
cabcabca
Sample Output
HINT
对于样例,我们可以利用"abc"不断自我连接得到"abcabcabc",读入的cabcabca,是它的子串
Source
bzoj1355: [Baltic2009]Radio Transmission的更多相关文章
- BZOJ1355: [Baltic2009]Radio Transmission KMP
Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...
- 【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 ...
- 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 ...
- BZOJ1355:[Baltic2009]Radio Transmission
浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...
- [bzoj1355][Baltic2009]Radio Transmission_KMP
Radio Transmissio bzoj-1355 Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Inp ...
随机推荐
- android开发 PopupWindow 设置充满屏幕
View qrcode_view = this.getLayoutInflater().inflate(R.layout.taskdetail_qrcode,null); final PopupWin ...
- HTTP - 内容编码
HTTP 应用程序有时在发送之前需要对内容进行编码.例如,在把很大的 HTML 文档发送给通过慢速连接上来的客户端之前,服务器可能就会对它进行压缩,这样有助于减少传输实体的时间. 内容编码过程 内容编 ...
- C#: Create a WebRequest with HTTP Basic Authentication
http://blog.csdn.net/huangyaoshifog/article/details/4470675 myReq = WebRequest.Create(url); string u ...
- centos nginx,php添加到Service
SHELL脚本: nginx vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx da ...
- Vim安装ctags插件
问题描述: 系统安装ctags插件 问题解决: (1)下载ctags插件 (2)新下载的ctags文件是一个tar包文件,使用tar -zxcf命令进行解压缩 注: 解压缩之后的 ctags文件,如上 ...
- jquery获取标签内容,编辑内容
一.获取页面元素 三种方式获取页面中元素的内容. input标签使用:.val()获取 标签下的html及文本内容:.html() 仅获取标签下的纯文本内容:.text() <head> ...
- linux杀掉80端口线程命令
80端口被其他程序占用, fuser -k -n tcp 80
- Unity3D–Texture图片空间和内存占用分析(转载)
原地址:http://www.unity蛮牛.com/home.php?mod=space&uid=1801&do=blog&id=756 Texture图片空间和内存占用分析 ...
- Android 解决ListView中每一项与button冲突
在listView的item里面如果有button,ImageButton等控件,会使得ListView不会被点击,解决方法是: ①在Button上面添加属性 android:focusable=&q ...
- Matlab中编译C++文件
今天在跑<Robust Object Tracking via Sparsity-based Collaborative Model>这篇文章的代码时候,发现出现如下错误: 发现错误时由于 ...