博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2185 Milking Grid [二维KMP next数组]
阅读量:6936 次
发布时间:2019-06-27

本文共 2403 字,大约阅读时间需要 8 分钟。

直接转田神的了:

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 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns.
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

* Line 1: Two space-separated integers: R and C
* 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

* Line 1: The area of the smallest unit from which the grid is formed

Sample Input

2 5ABABAABABA

Sample Output

2

Hint

The entire milking grid can be constructed from repetitions of the pattern 'AB'.

Source

题目链接:
题目大意:给你一个r行c列的字符矩阵,令其一个子矩阵,使得这个子矩阵无限复制成的大矩阵包含原矩阵,现求这个子矩阵的最小尺寸
题目分析:1.把每行字符串看作一个整体对行求next数组
                  2.将矩阵转置
                  3.进行操作1,注意这里的行是原来的列,列是原来的行,相当于求原来列的next数组
                  4.求出len-next[len]即最小不重复子串的长度作为子矩形的边长

 

13892851 Accepted 42452K 79MS 1707B 2015-02-16 10:51:05

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 13 #define N 100 14 #define M 10005 15 //#define mod 10000007 16 //#define p 10000007 17 #define mod2 1000000000 18 #define ll long long 19 #define LL long long 20 #define eps 1e-6 21 //#define inf 2147483647 22 #define maxi(a,b) (a)>(b)? (a) : (b) 23 #define mini(a,b) (a)<(b)? (a) : (b) 24 25 using namespace std; 26 27 int n,m; 28 char s[M][M]; 29 char c[M][M]; 30 int nexts[M]; 31 int nextc[M]; 32 int l; 33 int now; 34 35 void get_nexts() 36 { 37 int i,j; 38 i=0;j=-1;nexts[0]=-1; 39 while(i

 

转载于:https://www.cnblogs.com/njczy2010/p/4293817.html

你可能感兴趣的文章
取指定的字符串,字符串里面有汉字和字母
查看>>
华为招聘机试整理10:实现字符串中子字符串的替换
查看>>
VMware虚拟机上安装linux和克隆
查看>>
Python的open函数
查看>>
IDEA在debug时修改变量值
查看>>
Dell poweredge r210进BIOS改动磁盘控制器(SATA Controller)接口模式
查看>>
Go 1.5keyword搜索文件夹、文件、文件内容_修复一个小BUG
查看>>
20160205.CCPP体系具体解释(0015天)
查看>>
匈牙利算法解决二分图匹配
查看>>
.NET Core 2.0 单元测试中初识 IOptionsMonitor<T>
查看>>
关于内存中栈和堆的区别(非数据结构中的堆和栈,区别)
查看>>
redhat6.7在线安装postgresql9
查看>>
Advanced Installer 打包后,安装包在WIN10下重启后再次运行安装的解决办法
查看>>
js实现手机页面定位
查看>>
第三方Android 模拟器流畅速度快,适合开发人员
查看>>
UWP-消息提示(仿Android)
查看>>
控件UI性能调优 -- SizeChanged不是万能的
查看>>
【git】把本地项目和远程git仓库相连通
查看>>
028_rync和inotify实现实时备份
查看>>
JAVA 线程池之Callable返回结果
查看>>