POJ 2185 Milking Grid(KMP)】的更多相关文章

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…
题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接: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…
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…
题意:给出一个字符矩形,问找到一个最小的字符矩形,令它无限复制之后包含原来的矩形. 此题用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…
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一个AB 组成一个 ABABAB ABABAB 能够多出来 思路:每一行求出周期 总共n个 求这n个周期的最小公倍数 假设大于m 取m 每一列求出周期 总共m个求这个m个周期的最小公倍数 假设大于n取n 答案就是2个最小公倍数的积 #include <cstdio> #include <cst…
题目链接: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: 7153   Accepted: 3047 Description Every morning when they are milked, the Farmer John's cows form a rectangular grid tha…
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…