Milking Grid

Time Limit: 3000MS Memory Limit: 65536K

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 5

ABABA

ABABA

Sample Output

2

Hint

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

Source

USACO 2003 Fall

/*
kmp.
一开始传参数呵呵了.
忘了n和m相等的情况.
先把行看做一个整体做kmp.
然后把列看做一个整体做kmp.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 10001
#define MAXM 81
using namespace std;
int n,m,k,w,next[MAXN];
char g[MAXN][MAXM];
bool check(int x,int y,bool flag)
{
if(flag)
{
for(int i=1;i<=m;i++) if(g[x][i]!=g[y][i]) return false;
return true;
}
else
{
for(int i=1;i<=k;i++) if(g[i][x]!=g[i][y]) return false;
return true;
}
}
void kmp(int x,bool flag)
{
int p=0;
for(int i=2;i<=x;i++)
{
p=next[i-1];
while(p&&!check(i,p+1,flag)) p=next[p];
if(check(i,p+1,flag)) p++;
next[i]=p;
}
}
void slove()
{
kmp(n,1);k=n-next[n];
memset(next,0,sizeof next);
kmp(m,0);w=m-next[m];
return ;
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>g[i][j];
slove();
printf("%d\n",k*w);
return 0;
}

Poj 2165 Milking Grid(kmp)的更多相关文章

  1. POJ 2185 Milking Grid KMP循环节周期

    题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...

  2. POJ 2185 Milking Grid KMP(矩阵循环节)

                                                            Milking Grid Time Limit: 3000MS   Memory Lim ...

  3. POJ 2185 Milking Grid [KMP]

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8226   Accepted: 3549 Desc ...

  4. POJ 2185 Milking Grid(KMP)

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4738   Accepted: 1978 Desc ...

  5. [poj 2185] Milking Grid 解题报告(KMP+最小循环节)

    题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...

  6. POJ 2185 Milking Grid [二维KMP next数组]

    传送门 直接转田神的了: Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6665   Accept ...

  7. 题解报告:poj 2185 Milking Grid(二维kmp)

    Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...

  8. poj 2185 Milking Grid

    Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS   Memory Limit: 65536K       Descript ...

  9. POJ 2185 Milking Grid (KMP,求最小覆盖子矩阵,好题)

    题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接:http://poj.org/showmessage?message_id=153 ...

随机推荐

  1. mysql查看表结构命令,如下:

    desc 表名; show columns from 表名; describe 表名; show create table 表名;

  2. (二)XML基础(2)

    三.解析 服务端解析 JDK:            DOM            SAX            JAXB    java and xml Binding 开源(一般都是用开源的)   ...

  3. SqlServer用sql语句清理log日志

    原文:SqlServer用sql语句清理log日志 USE[master] ALTER DATABASE [Center] SET RECOVERY SIMPLE WITH NO_WAIT ALTER ...

  4. 前端开发 Vue -2npm

    npm介绍 说明:npm(node package manager)是nodejs的包管理器,用于node插件管理(包括安装.卸载.管理依赖等) 使用npm安装插件:命令提示符执行npm instal ...

  5. javascript的装载和执行

    前言 为什么要采用js来create一个script标签,设置src然后append到head中,而不是直接使用script标签,这样不是更简单点吗? javascript的装载和执行 首先,我想说一 ...

  6. MYSQL编码转换的问题latin1转utf8

    1.先导出 mysqldump --default-character-set=latin1 --create-options=false --set-charset=false  -u root - ...

  7. 用javafx webview 打造自己的浏览器

    背景 项目需要做一个客户端的壳,内置浏览器,访问指定 的url 采用技术 java 1.8 开始吧! java环境配置略 hello world import javafx.application.A ...

  8. tomcat压缩配置

    问题描述:HPS打开登录页面(也就是用户输入用户名和密码的页面),要加载数据和程序,大概2M大小,在网络不好的情况下,要10几秒甚至几十秒,公司内网测试需要:3秒多 解决方法: 1. 打开登录页面,用 ...

  9. django 新项目

    1.创建虚拟环境 mkvirtualenv - p  python3 2.pycharm : 在pycharm中新建项目, 取名.添加虚拟机上的虚拟环境

  10. Js调用本地exe的方式

    1.     使用记事本(或其他文本编辑器)创建一个myprotocal.reg文件,并写入以下内容 Windows Registry Editor Version 5.00 [HKEY_CLASSE ...