题解报告: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 ...
随机推荐
- [React] PureComponent in React
In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...
- Hibernate中的自己定义类型——UserType、CompositeUserType
一.UserType Hibernate拥有自己定义映射表属性的机制.主要通过实现接口UserType,详细的UserType: import java.sql.PreparedStatement; ...
- 微信小程序实战之 pay(支付页面)
项目目录: 逻辑层: pay.js // pages/pay/pay.js Page({ /** * 页面的初始数据 */ data: { resultType: "", resu ...
- Mapreduce运行过程分析(基于Hadoop2.4)——(三)
4.4 Reduce类 4.4.1 Reduce介绍 整完了Map,接下来就是Reduce了.YarnChild.main()->ReduceTask.run().ReduceTask.run方 ...
- Cleave js 使用
1111111111111111 xxxxxx Cleave.js 键入时格式化< input />内容 信用卡号码格式 明确 美国运通:从34/37开始 34 签证:从4开始 ...
- AIX下RAC搭建 Oracle10G(五)安装oracle、建立监听
AIX下RAC搭建系列 AIX下RAC搭建 Oracle10G(五)安装oracle.建立监听 环境 节点 节点1 节点2 小机型号 IBM P-series 630 IBM P-series 630 ...
- android真机调试 INSTALL_FAILED_MEDIA_UNAVAILABLE 问题解决方案
前提是手机用数据线连到电脑,安装好手机对应的驱动. 1:打开cmd 2:cd切换到sdk安装目录的platform-tools目录,比如我安装到了D盘根目录,则输入: cd d:\android-sd ...
- Node-webkit 介绍
什么是Node-webkit ? Node-webkit 是Intelproject师rogerwang写的一个基于node.js和chromium的应用程序执行环境,通过node-webkit,我们 ...
- 变量的命名和if语句
1. 计算机是什么 基本组成: cpu: 主频, 核数(16) 内存:大小(8G, 16G, 32G) 型号: DDR3, DDR4, DDR5, 主频(海盗船,玩家国度) 显卡: 显存.型号(N- ...
- php判断手机号码
//PHP判断手机号码 public function isMobile($params) { $pattern = "/^(13[0-9]|14[0-9]|15[0-9]|17[0-9 ...