字符串KMP || POJ 2185 Milking Grid】的更多相关文章

求一个最小矩阵,经过复制能够覆盖原矩阵(覆盖,不是填充,复制之后可以有多的) *解法:横着竖着kmp,求最大公倍数的做法是不对的,见http://blog.sina.com.cn/s/blog_69c3f0410100tyjl.html 正解如http://poj.org/showmessage?message_id=153316 求出每一行的可以重复的子串长度,所有行都可以的(公共的)那个最小的长度就是最终所求矩阵的宽 求出宽之后把剩下那些列砍掉,然后要求矩阵的高,把每行看作一个整体kmp即可…
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一个AB 组成一个 ABABAB ABABAB 能够多出来 思路:每一行求出周期 总共n个 求这n个周期的最小公倍数 假设大于m 取m 每一列求出周期 总共m个求这个m个周期的最小公倍数 假设大于n取n 答案就是2个最小公倍数的积 #include <cstdio> #include <cst…
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6665   Accepted: 2824 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <…
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expe…
Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4738   Accepted: 1978 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75…
                                                        Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7153   Accepted: 3047 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid tha…
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently wri…
Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8226   Accepted: 3549 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75…
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS   Memory Limit: 65536K       Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) co…
题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接:http://poj.org/showmessage?message_id=153316http://blog.sina.com.cn/s/blog_69c3f0410100tyjl.html 在discuss里还看到有人说可以这么简化:求横向最小长度时每次比较整列求纵向最小长度时每次比较整行真的是太神了!http://poj.org/showmessage?message_id…
http://poj.org/problem?id=2185 题意: 给出一个r行c列的字符矩阵,求最小的覆盖矩阵可以将原矩阵覆盖,覆盖矩阵不必全用完. 思路: 我对于字符串的最小循环节是这么理解的: 如果next[12]=5,那么前5个前缀字符和后5个后缀字符是一样,但是此时还需要加上中间的2个,所以循环节为7. 如果next[12]=7,那么中间2个既出现在了前缀里,也出现在了后缀里,所以中间的2个字符等于开头的两个字符.此时循环节为5. 这样的话,字符串的最小循环节就是 len - nex…
题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next函数的应用.需要枚举每一行每一列的字符串所对应的的 nxt[] 值,然后通过分析计算出最小的宽和最小的高. 具体分析 参考链接:https://blog.csdn.net/u013686535/article/details/52197467 一看这题,容易想出一种很直观的做法:求出每一行的最小重复…
题意:给出一个字符矩形,问找到一个最小的字符矩形,令它无限复制之后包含原来的矩形. 此题用KMP+枚举来做. 一维的字符串匹配问题可以用KMP来解决.但是二维的就很难下手.我们可以将二维问题转化为一维来做. 首先可以发现这个最小的字符矩形一定是在左上角的. 这样我们对每列枚举它的前缀的长度,如果是能形成重复子串,就记录一下该长度.为了能形成矩形,统计出现R次的最短长度L(一定会有出现R次的长度,最坏的情况下这个长度是C). 比如: ABCABCABC(长度为3和9的前缀可以形成重复子串) ABA…
题意:求最小的循环矩形 思路:分别求出行.列的最小循环节,乘积即可. #include<iostream> #include<stdio.h> #include<string.h> using namespace std; ]; int r,c; ][]; bool equalR(int i,int j){//行相等 int k; ;k<c;++k) if(str[i][k]!=str[j][k])return false; return true; } bool…
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is q…
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently wri…
Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时,有最小循环节(就是最小覆盖子串). 快照: 我对KMP的一些理解(lyp点拨的):pre[i](或next[i])的实质是串str[1..i]的最长且小于i的“相等前.后缀”分别为str[1..pre[i]](前缀)与str[(i-pre[i]+1)..i](后缀),通俗讲就是:使str[1..i…
Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8314   Accepted: 3586 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75…
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最小覆盖矩阵的面积. analyse: 做了上一篇博客的题目,就会求一个字符串的最小覆盖矩阵.同样的,现在求字符矩阵的最小覆盖矩阵,只是将一维推向了二维,我们在纸上画一下图,你会发现,其实二维的也是so easy! 我们将每一行的字符串的最小覆盖子串求出来,然后对这n个数求LCM,那么结果就是行覆盖的…
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently wri…
Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10084   Accepted: 4371 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 7…
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is q…
Milking Grid POJ - 2185 时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns.…
题意 POJ2185 数据加强版 描述 Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is curre…
Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2287    Accepted Submission(s): 713 Problem Description Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious.For…
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, pu…
模板—字符串—KMP(单模式串,单文本串) Code: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 1000010 int f[N],n,ans,len1,len2; char str1[N],str2[N]; int main() { scanf("%s%s",str2+1,str1+1),len1=strlen(s…
题意:给定一个由字符组成的矩阵,求出它的面积最小的覆盖矩阵.(感觉应该是可重叠的......* (・ω・)っ) 解法:KMP.行列互不影响,可以问题分解.先求出每一行的最小重复串,利用kmp中的next[ ]数组,然后求其最小公倍数.若变成最大值就可以break了,这也是我代码本来应该O(2*m*n),但却32ms很快的原因......(๑•ᴗ•๑) 于是同样地求每一列的最小重复串,再求最小公倍数.最终2个答案相乘就行了. P.S.这题我十分纠结,也有人说poj数据水......但我还是AC了~…
奶牛矩阵 题目大意:给定一个矩阵,要你找到一个最小的矩阵,这个矩阵的无限扩充的矩阵包含着原来的矩阵 思路:乍一看这一题确实很那做,因为我们不知道最小矩阵的位置,但是仔细一想,如果我们能把矩阵都放在左上角该多好,这样一来这一题好像又是循环数组那个样子了(二维的). 而事实上我们确实可以把所有情况都放在左上角,因为矩阵里面的元素的相对位置是不变的,这样一来我们就可以把矩阵看成都是一些元素从左上角往右下角扩充.那么现在问题就又回到了循环节的问题上了,我们可以把矩阵看成是很多很多个字符串组成,我们要找的…
题目链接:http://poj.org/problem?id=2185 题意:给出一个R*C(10000 * 75)的矩形字符串,然你求最小的不严格重复矩阵,比如,ABA,最小的重复矩阵是AB,经过复制ABAB,可以把ABA完全覆盖掉. 题解: 题意很好理解,首先我们应该清楚,最小重复字串一定实在左上角.我们可以找到宽的最小共同重复串,然后,我们就可以对高进行kmp.答案即为w*h的值.对于宽,我们可以暴力找,枚举每一行的所有起点为0的字串,判断该长度是否满足重复,然后,我们所有行的最小共同的重…