poj1961 Period】的更多相关文章

/** 题目:poj1961 Period 链接:http://poj.org/problem?id=1961 题意:求从1到i这个前缀(2<=i<=N) ,如果有循环节(不能自身单独一个),输出前缀字符串长度以及最大的循环周期: 思路: 参考自:http://www.cnblogs.com/chenxiwenruo/p/3546457.html 定理:假设S的长度为len,则S存在最小循环节,循环节的长度L为len-next[len],子串为S[0…len-next[len]-1]. (1)…
两道题都是求循环节的...但是一道是学哈希时做的,另一道是学$KMP$时做的 POJ2604 用的哈希...枚举长度的因数作为循环节的长度,然后暴力算出所有循环节位置的哈希值,看看是否相等. #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cctype> #include<cstd…
我们考虑KMP算法中fail失配指针的意义. 对于一个模式串(Pattern),位置i对应的失配指针fail[i]是那个位置: 这个位置满足的条件是,子串[0, fail[i])是位置i(不含)的后缀,并且fail[i]是所有满足此条件的位置中最靠后(最接近i)的那个. 也就说当我们用模式串P匹配文本串T的时候,我们检查当前位置T[i]与P[j]是否匹配, 若匹配i,j指针各向前移动一位: 否则,利用模式子串[0, j)与文本子串i(不含)的后缀已经匹配的信息,保持i指针不变,j指针退到fail…
题意 求字符串s的最小循环元长度和循环次数 思路 s[1~i]满足循环元要len能整除i并且s[len+1~i]=s[1~i-len] 代码 #include<cstdio> #include<algorithm> #include<cstring> #define N 1000005 using namespace std; char s[N]; int next[N]; int n,T; int len; void kmp() { next[]=; ,j=;i<…
题面 一个字符串的前缀是从第一个字符开始的连续若干个字符,例如"abaab"共有5个前缀,分别是a, ab, aba, abaa, abaab. 我们希望知道一个N位字符串S的前缀是否具有循环节.换言之,对于每一个从头开始的长度为 i (i 大于1)的前缀,是否由重复出现的子串A组成,即 AAA...A (A重复出现K次,K 大于 1).如果存在,请找出最短的循环节对应的K值(也就是这个前缀串的所有可能重复节中,最大的K值). 算法 我们看到这个前缀 自然想到了KMP中的next数组(…
[POJ1961]period 题目描述 如果一个字符串S是由一个字符串T重复K次构成的,则称T是S的循环元.使K出现最大的字符串T称为S的最小循环元,此时的K称为最大循环次数. 现在给定一个长度为N的字符串S,对S的每一个前缀S[1~i],如果它的最大循环次数大于1,则输出该循环的最小循环元长度和最大循环次数. 输入 多组数据,每个数据包括两行.第一行为字符串大小N,第二行包括字符串.输入最后一行以0结尾. 输出 第一行"Test case #"+测试数据第几组,对于每个周期K>…
KMP算法 next数组的求法 void calc_next() { next[]=; , j=; i<=n; ++i) { &&a[i]!=a[j+]) j=next[j]; ]) ++j; next[i]=j; } } f数组的求法 void calc_next() { , j=; i<=m; ++i) { && (j==n || b[i]!=a[j+])) j=next[j]; ]) ++j; f[i]=j; //if (f[i]==n) //此时就是A在…
[题解]PERIOD - Period [POJ1961] [SP263] 在进入这道题之前,我们需要了解 kmp 算法 不知道的童鞋可以去看一下Silent_EAG(一个可爱的女孩纸)的讲解. 关于 kmp 算法中 next 数组的周期性质 引理: 对于某一字符串 \(S[1\)-\(i ]\),在它众多的\(next[ i ]\)的"候选项"中,如果存在某一个\(next[ i ]\),使得: \(i\) % \(( i - next[ i ] ) == 0\) ,那么 \(S[…
UVA1328 Period 其他链接:luogu UVA1328 POJ1961 For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (\(2 \le i…
Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20436   Accepted: 9961 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the…
浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html 题目传送门:http://poj.org/problem?id=1961 根据研究发现,如果一个字符串可以被若干个字符串首尾相连拼接而成,那么必然存在\(nxt_n\ne0,n\ mod\ (n-nxt_n)=0\) 求一遍\(nxt\)数组就行了. 时间复杂度:\(O(n)\) 空间复杂度:\(O(n)\) 代码如下: #include <cstdio> using namespa…
我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expired. [SQLSTATE 07008] (Error 121)  OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Communication link failur…
今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred within the report server database.  This may be due to a connection failure, timeout or low disk condition within the database.;".检查C:\Program Files\Micro…
Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 16776   Accepted: 8077 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the…
本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold time)中找到. 系列目录      时序收敛:基本概念     建立时间和保持时间(setup time 和 hold time)     OFFSET约束(OFFSET IN 和OFFSET OUT)     Clock Skew , Clock uncertainly 和 Period     特…
传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i.e. S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1. String u,w are matched if for each number i, occ(u,i)=occ(w,i) always holds. i.e. (1,2,2,1,3)≍(1,3,…
Period 题目大意:给定一个字符串,要你找到前缀重复了多少次 思路,就是kmp的next数组的简单应用,不要修正next的距离就好了,直接就可以跳转了 PS:喝了点酒用递归实现除法和取余了...结果tle不知道怎么回事... #include <iostream> #include <functional> #include <algorithm> #include <string> using namespace std; typedef int Po…
cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version></version> <configu…
/** * get period for last year * @param time * @return */ public static DatePeriodDTO getLastYear(long time) { Calendar calendar = Calendar.getInstance(); //get last year calendar.add(Calendar.YEAR, -1); int lastYear = calendar.get(Calendar.YEAR); ca…
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" 或者 SqlClient Class , 你在执行一个很费时的SQL 操作时候,可能就会碰到下面的超时异常. --------------------------- ---------------------------Timeout expired.  The timeout period elapsed…
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefi…
[LA3026]Period 试题描述 For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ≤ i ≤ N) we want to know the l…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2120    Accepted Submission(s): 1039 Problem Description For each prefix of a given string S with N characters (each character has an ASCI…
背景: 在最近开发中遇到一个问题,对一个数据库进行操作时,我采用64个并行的任务每个任务保证一个数据库连接对象:但是每个任务内部均包含有24个文件需要读取,在读取文件之后,我们需要快速将这24个文件批量入库到数据库中. 于是我这样开发我的程序: 主任务处理方式:最多允许64并行主任务: 主任务内部子任务采用串行方式:24个文件依次读取,和当前主任务均使用同一个数据库连接字符串. 每个主任务都需要24个文件入库到各自的物理分表中,采用的是串行读取文件资源,串行入库,没有能并行插入24个批处理文件到…
After a period of struggle , i decided to follow the teacher Chen learning . Say true i really dislike learn a new programming language . Because I have learned several programming languages, but not very proficient in every one . So I decided to in…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2866    Accepted Submission(s): 1433 Problem Description For each prefix of a given string S with N characters (each character has an ASCI…
题目链接 找循环位数是奇数的数有多少个 这个自己很难写出来,完全不能暴力 维基百科链接 维基百科上面说的很好,上面的算法实现就好了. 就是上面的 Java程序: package project61; public class P64{ void run(){ int count = 0; int m = 0; int d = 1; int a0 = 0; int a = 0; int period = 0; for(int S = 2;S<10000;S++){ period = 0; m =…
如何设置适当的值并不轻易. 首先,假如要使用大量线程的话,ramp-up period 一般不要设置成零. 因为假如设置成零,Jmeter将会在测试的开始就建立全部线程并立即发送访问请求, 这样一来就很轻易使服务器饱和,更重要的是会隐性地增加了负载,这就意味着服务器将可能过载,不是因为平均访问率高而是因为所有线程的第一次并发访问而引起的不正常的初始访问峰值,可以通过Jmeter的聚合报告监听器看到这种现象.这种异常不是我们需要的,因此,确定一个合理的ramp-up period 的规则就是让初始…
UVAlive 3026 Period 题目: Period   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive…
Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输出k即周期数: Sample Input 3 aaa 12 aabaabaabaab 0   Sample Output Test case #1 2 2 3 3   Test case #2 2   2 6   2 9   3 12  4  题目其实是来自于LA的..挺好的一道题,用的是原版的kmp.. 写…