题解报告:poj 2185 Milking Grid(二维kmp)
Description
Help FJ find the rectangular unit of smallest area that can be repetitively tiled to make up the entire milking grid. Note that the dimensions of the small rectangular unit do not necessarily need to divide evenly the dimensions of the entire milking grid, as indicated in the sample input below.
Input
* Lines 2..R+1: The grid that the cows form, with an uppercase letter denoting each cow's breed. Each of the R input lines has C characters with no space or other intervening character.
Output
Sample Input
2 5
ABABA
ABABA
Sample Output
2
Hint
#include<string.h>
#include<cstdio>
const int row_maxn=;
const int col_maxn=;
int row,col,row_prefix[row_maxn],col_prefix[col_maxn];
char mp[row_maxn][col_maxn],tmp[col_maxn][row_maxn];
void get_row_prefix(){
int i=,j=-;
row_prefix[]=-;
while(i<row){
if(j==-||!strcmp(mp[i],mp[j]))row_prefix[++i]=++j;
else j=row_prefix[j];
}
}
void get_col_prefix(){
int i=,j=-;
col_prefix[]=-;
while(i<col){
if(j==-||!strcmp(tmp[i],tmp[j]))col_prefix[++i]=++j;
else j=col_prefix[j];
}
}
int main(){
while(~scanf("%d%d",&row,&col)){
for(int i=;i<row;++i)scanf("%s",mp[i]);
for(int i=;i<row;++i)
for(int j=;j<col;++j)
tmp[j][i]=mp[i][j];
get_row_prefix();
get_col_prefix();
printf("%d\n",(row-row_prefix[row])*(col-col_prefix[col]));
}
return ;
}
题解报告:poj 2185 Milking Grid(二维kmp)的更多相关文章
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- Match:Milking Grid(二维KMP算法)(POJ 2185)
奶牛矩阵 题目大意:给定一个矩阵,要你找到一个最小的矩阵,这个矩阵的无限扩充的矩阵包含着原来的矩阵 思路:乍一看这一题确实很那做,因为我们不知道最小矩阵的位置,但是仔细一想,如果我们能把矩阵都放在左上 ...
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- POJ 2185 - Milking Grid (二维KMP)
题意:给出一个字符矩形,问找到一个最小的字符矩形,令它无限复制之后包含原来的矩形. 此题用KMP+枚举来做. 一维的字符串匹配问题可以用KMP来解决.但是二维的就很难下手.我们可以将二维问题转化为一维 ...
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- 【KMP】POJ 2185 Milking Grid -- Next函数的应用
题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next ...
- POJ 2185 Milking Grid KMP(矩阵循环节)
Milking Grid Time Limit: 3000MS Memory Lim ...
- POJ 2185 Milking Grid(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
随机推荐
- HTML5 <template>标签元素简介
一.HTML5 template元素初面 <template>元素,基本上可以确定是2013年才出现的.干嘛用的呢,顾名思意,就是用来声明是“模板元素”. 目前,我们在HTML中嵌入模板H ...
- [Javascript] Link to Other Objects through the JavaScript Prototype Chain
Objects have the ability to use data and methods that other objects contain, as long as it lives on ...
- Android系统改动时间格式为24小时制
1. frameworks/base/packages/SettingsProvider/res/values/defaults.xml 添加<stringname="time_12_ ...
- JSP中的编译指令和动作指令的差别
JSP中的编译指令和动作指令的差别 1.编译指令是通知Servlet引擎的处理消息.而动作指令仅仅是执行时的脚本动作 2.编译指令是在将JSP编译成Servlet时起作用,而动作指令可替换成JSP脚本 ...
- Hibernate之三态篇
一.概况 (一)瞬时状态(暂时态) 在对象中假设对象刚被创建但没有被持久化的话就是瞬时态 特点: (1) 不和 Session 实例关联 (2)在数据库中没有和瞬时对象关联的记录 (二)持久状态 持久 ...
- YII获取当前URL
<?php //当前域名 echoYii::app()->request->hostInfo; //除域名外的URL echoYii::app()->request ...
- 偶遇HiWork,请不要擦肩而过
非常多朋友可能都不了解HiWork,在这里介绍一下. HiWork是基于云存储的团队即时沟通协作平台,主要针对于中小团队及中小企业的即时沟通,让团队沟通更顺畅.在HiWork平台可即时得知所使用第三方 ...
- C# 敏感词过滤
public class BadWordFilter { #region 变量 private HashSet<string> hash = new HashSet<string&g ...
- XMU 1617 刘备闯三国之汉中之战 【BFS+染色】
1617: 刘备闯三国之汉中之战 Time Limit: 1000 MS Memory Limit: 128 MBSubmit: 6 Solved: 5[Submit][Status][Web B ...
- POJ1417 True Liars —— 并查集 + DP
题目链接:http://poj.org/problem?id=1417 True Liars Time Limit: 1000MS Memory Limit: 10000K Total Submi ...