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. asp.net core-14.JWT认证授权 生成 JWT Token

    源码下载 语言组织能力不好 ,看这个 视频 用visual studio code打开文件,运行dotnet watch run 之后在postman里面去访问 拿到Token后

  2. awr报告没有数据11.2.0.3

    有个朋友,反馈AWR没有数据: 咨询版本:oracle企业版本11.2.0.3 SQL> select * from v$version; BANNER -------------------- ...

  3. C# 对象互转

    /// <summary> /// 适用于初始化新实体 /// </summary> static public T RotationMapping<T, S>(S ...

  4. (二)Struts.xml文件详解

    一.Struts.xml文件 Struts.xml文件构成 如图,<Struts>标签内共有5个子标签. 1.1 struts-default.xml 查看Struts的内容可知,Stru ...

  5. 利用贝叶斯算法实现手写体识别(Python)

    在开始介绍之前,先了解贝叶斯理论知识 https://www.cnblogs.com/zhoulujun/p/8893393.html 简单来说就是:贝叶斯分类是一类分类算法的总称,这类算法均以贝叶斯 ...

  6. [C#] LINQ之SelectMany和GroupJoin

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. vue引入警告:There are multiple modules with names that only differ in casing. This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. Use equal casing. Compare these

    在写vue项目的时候 当我使用 : import dataSource from '../overseaProduct/house/dataSource'; 引入dataSource文件的时候:控制台 ...

  8. QTabWidget标签实现双击关闭(转)

    重载了QTabWidget(由于tabBar()是protected),这样就可以获取到标签了. 1 class Tab : public QTabWidget 2 { 3 Q_OBJECT 4 pu ...

  9. Seaborn(二)之数据集分布可视化

    Seaborn(二)之数据集分布可视化 当处理一个数据集的时候,我们经常会想要先看看特征变量是如何分布的.这会让我们对数据特征有个很好的初始认识,同时也会影响后续数据分析以及特征工程的方法.本篇将会介 ...

  10. Oracle11g数据库导入Oracle10g操作成功

    转自:https://wenku.baidu.com/view/1b652b57f7ec4afe04a1dfb8.html