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 ...
随机推荐
- 被git extensions给坑了,Not owner 解决办法
我只遇到这一种情况,不能访问git文件主库, 清空以前的历史文件,包括默认配置文件,重新安装一遍git extension,然后设置账号和密码, 在打开bash设置私钥和公钥 把公钥添加到你的git的 ...
- Codeforces Round #303 (Div. 2) E. Paths and Trees 最短路+贪心
题目链接: 题目 E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes inputs ...
- Window7中Eclipse运行MapReduce程序报错的问题
按照文档:http://www.micmiu.com/bigdata/hadoop/hadoop2x-eclipse-mapreduce-demo/安装配置好Eclipse后,运行WordCount程 ...
- linux cmake 安装mysql5.5.11,以及更高版本
1.下载mysql5.5.12和cmake wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.12-linux2.6-i686.tar.gz ...
- hdu 1166 树状数组 线段树入门
点修改 区间求和 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...
- 原 Linux搭建SVN 服务器
原 Linux搭建SVN 服务器 发表于1年前(2014-08-05 17:55) 阅读(12257) | 评论(3) 31人收藏此文章, 我要收藏 赞3 摘要 Linux搭建SVN 服务器 目录 ...
- Oracle composite index column ordering
Question: I have a SQL with multiple columns in my where clause. I know that Oracle can only choos ...
- httpclient发送multipart/form-data类型参数和用MultipartRequest接收参数
一.利用HttpClient发送基于Content-Type="multipart/form-data"形式的表单 package com.test.httpclient; imp ...
- 纯互联网项目“失宠”乐博资本杨宁称今后只投O2O
从去年开始,我们接下来会进入全新的时代,就是智能一切的时代!过去的互联网都在电脑里,都在服务器里,包括现在移动云也是,大数据都是在服务器里面,真正我们身边的东西,智能含量是非常低的.包括你家洗衣机.冰 ...
- JVM基础学习
public class TestJVM { // 运行时数据区[方法区.堆.程序计数器.虚拟机栈.本地方法栈] private static int _1M = 1024 * 1024; publi ...