POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 6169 | Accepted: 2573 |
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
Source
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int row =;
- const int cow =;
- char str[row][cow];
- int next[row][cow];
- int RR,CC;
- int main()
- {
- while(scanf("%d%d",&RR,&CC)!=EOF)
- {
- for(int i=;i<RR;i++)
- scanf("%s",str[i]);
- int i,j,k;
- //先求出每一行的next
- int max_row=-;
- for(k=;k<RR;k++)
- {
- i=; j=-;
- next[k][]=-;
- while(i<CC)
- {
- if(j==-||str[k][i]==str[k][j])
- {
- i++;
- j++;
- next[k][i]=j;
- }
- else j=next[k][j];
- }
- if(max_row<(CC-next[k][CC]))
- max_row=(CC-next[k][CC]);
- }
- int max_cow=-;
- //求出所有列中的最小循环节
- for(k=;k<CC;k++)
- {
- i=;
- j=-;
- next[][k]=-;
- while(i<RR)
- {
- if(j==-||str[i][k]==str[j][k])
- {
- i++;
- j++;
- next[i][k]=j;
- }
- else
- j=next[j][k];
- }
- if(max_cow<(RR-next[RR][k]))
- max_cow=(RR-next[RR][k]);
- }
- printf("%d\n",max_row*max_cow);
- }
- return ;
- }
POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)的更多相关文章
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- 依据矩阵的二维相关系数进行OCR识别
我想通过简单的模板匹配来进行图像识别. 把预处理好的字符图片,分别与A到Z的样本图片进行模板匹配. 结果最大的表明相关性最大,就能够识别字符图片了. 在实际应用中.我用了openCV的matchTem ...
- 牛客练习赛1 矩阵 字符串二维hash+二分
题目 https://ac.nowcoder.com/acm/contest/2?&headNav=www#question 解析 我们对矩阵进行二维hash,所以每个子矩阵都有一个额hash ...
- 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都依照从左到右的递增的顺序排序,输入这种一个数组和一个数,推断数组中是否包括这个数
// 二维数组中的查找,杨氏矩阵在一个二维数组中.每行都依照从左到右的递增的顺序排序. // 每列都依照从上到下递增的顺序排序.请完毕一个函数,输入这种一个数组和一个数.推断数组中是否包括这个数 #i ...
- 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...
- POJ 2185 Milking Grid KMP(矩阵循环节)
Milking Grid Time Limit: 3000MS Memory Lim ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
随机推荐
- Spark学习(一)--RDD操作
标签(空格分隔): 学习笔记 Spark编程模型的两种抽象:RDD(Resilient Distributed Dataset)和两种共享变量(支持并行计算的广播变量和累加器). RDD RDD是一种 ...
- TortoiseGit中push的使用
https://tortoisegit.org/docs/tortoisegit/tgit-dug-push.html Options Force (May discard known changes ...
- ASP.NET四则运算--策略模式
在ASP.NET中实现四则运算,同样使用了类的封装,以及策略模式.只不过是把封装的类.前台代码以及后台的代码分离开来,但同样是要达到功能的实现. Calculator.cs using System; ...
- Music Player团队项目(一)
团队成员及分工 团队: Blue 团队共有六人 姓名: 学号后四位: 贡献分: 张 宇(队长) 1152 1+1.8=2.8分 侯贺琦 1 ...
- OpenCV installation on Linux
Getting the Cutting-edge OpenCV from the Git Repository Launch Git client and clone OpenCV repositor ...
- iOS问题处理:如何在Mac下显示Finder中的所有文件
摘自:http://www.cnblogs.com/elfsundae/archive/2010/11/30/1892544.html 在Unix下工作,你可能需要处理一些“特殊“文件或文件夹,例如/ ...
- 期权交易基本原理——买进看跌期权(Long Put),卖出看跌期权(Short Put)
期权交易基本原理--买进看跌期权(Long Put),卖出看跌期权(Short Put) 来源:中电投先融期货-青岛 浏览:13508次2014-07-25 14:25:55 3 第三节 买进看跌期权 ...
- Nginx模块学习之————accesskey权限模块使用(Nginx防盗链详细解说),防止别人下载文件和图片
nginx 的第三方模块ngx_http_accesskey_module 来实现下载文件的防盗链 1.具体安装教程:http://www.cnblogs.com/tinywan/p/5983694. ...
- HIHO 线段树(单点)
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> ...
- box-shadow使用指南
Summary The box-shadow property describes one or more shadow effects as a comma-separated list. It e ...