poj 2185 Milking Grid
| Time Limit: 3000MS | Memory Limit: 65536K | |
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<cstdio>
#include<iostream>
#define scale 26
using namespace std;
int n,m;
int a[10001][76];
long long horizontal[10001],vertical[77];
int fh[10011],fv[81];
void kmp()
{
for(int i=1;i<n;i++)
{
int j=fh[i];
while(j&&horizontal[j]!=horizontal[i]) j=fh[j];
fh[i+1]= horizontal[i]==horizontal[j] ? j+1 : 0 ;
}
for(int i=1;i<m;i++)
{
int j=fv[i];
while(j&&vertical[i]!=vertical[j]) j=fv[j];
fv[i+1]= vertical[i]==vertical[j] ? j+1 : 0 ;
}
}
int main()
{
scanf("%d%d",&n,&m);
char c;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>c;
a[i][j]=c-'A'+1;
horizontal[i-1]=horizontal[i-1]*scale+a[i][j];
vertical[j-1]=vertical[j-1]*scale+a[i][j];
}
kmp();
printf("%d",(n-fh[n])*(m-fv[m]));
}
poj 2185 Milking Grid的更多相关文章
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- [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(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
- 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: 8226 Accepted: 3549 Desc ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- POJ 2185 Milking Grid (KMP,求最小覆盖子矩阵,好题)
题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接:http://poj.org/showmessage?message_id=153 ...
- POJ 2185 Milking Grid(KMP最小循环节)
http://poj.org/problem?id=2185 题意: 给出一个r行c列的字符矩阵,求最小的覆盖矩阵可以将原矩阵覆盖,覆盖矩阵不必全用完. 思路: 我对于字符串的最小循环节是这么理解的: ...
随机推荐
- 关于localStorage 应用总结
window.localStorage 设置数据几种方式 1.localStorage.setItem('name',c); 2.localStorage.name=c; 3.localStorage ...
- linux安全配置学习
参考摘自https://www.cnblogs.com/hiccup/p/4300963.html 1.关闭icmp请求 #vm虚拟机是130地址,通过echo 1 > /proc/sys/ne ...
- Delphi 获取Ip地址的方法总结
通过注册表获取或修改Ip 想到Windows会把系统网卡相关信息存入注册表,肯定可通过注册表读取具体ip信息.大致思路是找HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...
- CentOS 6.5以上版本安装mysql 5.7 完整版教程(修订版)
转载自:https://codeday.me/collect/20170524/21861.html 1: 检测系统是否自带安装mysql # yum list installed | grep my ...
- 实现LinearLayout(垂直布局,Gravity内容排布)
首先上Gravity的代码,Android原版的Gravity搞得挺复杂的,太高端了.但基本思路是使用位运算来做常量,我就自己消化了一些,按自己的思路来实现. 先上代码,在做分析. package k ...
- scala 有 + 运算符吗? - 03
scala 有运算符吗? 答案是没有. package com.msym /** * Created by ACER on 2017/7/4. */ object Demo { def main(ar ...
- java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
微信小程序前后台使用get方式传参时报错如图.但在微信开发平台和苹果测试都没事,在安卓手机上就报这个错,猜想原因是get传递了汉字的原因. 尝试了下在后台输出从前台获取的参数,但是后台什么也没有获取到 ...
- BZOJ5006 THUWC2017随机二分图(概率期望+状压dp)
下称0类为单边,1类为互生边,2类为互斥边.对于一种匹配方案,考虑其出现的概率*2n后对答案的贡献,初始为1,如果有互斥边显然变为0,否则每有一对互生边其贡献*2.于是有一个显然的dp,即设f[S1] ...
- Ifter Party LightOJ - 1014(水题)
题意:有C个人,给P个食物,每人吃Q个,剩L个.然后给你P和L(Q>L),让你求Q的可能情况,如果有多种可能,从小到大输出:如果不存在,输出impossible 就是求写出公式 遍历c求P-L的 ...
- STL Set和multiset 容器
STL Set和multiset 容器 set/multiset的简介 set是一个集合容器,其中所包含的元素是唯一的,集合中的元素按一定的顺序排列. 元素插入过程是按排序规则插入,所以不能指定插入位 ...