Milking Grid
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 7153   Accepted: 3047

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'.
 
题意:找出矩阵中最小的子矩阵,满足循环它能形成包括原矩阵的矩阵
题解:
       对于每一行,当作一个字符,跑kmp,若有hang[n]!=0 则有循环节,则行最短循环节长度=小矩阵的高=n-hang[n]
    对于列也是如此
//作者:1085422276
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
//#include<bits/stdc++.h>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
const int inf = ;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
ll temp,p;
if(b==)
{
x=;
y=;
return a;
}
p=exgcd(b,a%b,x,y);
temp=x;
x=y;
y=temp-(a/b)*y;
return p;
}
//*******************************
char mp[][];
int n,m,p[];
int is_equal(int i,int j)
{
for(int k=;k<m;k++)
{
if(mp[i][k]!=mp[j][k])return ;
}
return ;
}
int is_equaf(int i,int j)
{
for(int k=;k<n;k++)
{
if(mp[k][i]!=mp[k][j])return ;
}
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(p,,sizeof(p));
for(int i=;i<n;i++)
{
scanf("%s",mp[i]);
}
// for(int i=1;i<=n;i++)cout<<mp[i]<<endl;
//return 0;
int j=;
for(int i=;i<m;i++)
{
while(j&&!is_equaf(i,j))j=p[j];
if(is_equaf(i,j))j++;
p[i+]=j;
}
int l;
l=m-(p[m]);
memset(p,,sizeof(p));
j=;
for(int i=;i<n;i++)
{
while(j&&!is_equal(i,j))j=p[j];
if(is_equal(i,j))j++;
p[i+]=j;
}
int r;
r=n-(p[n]);
cout<<l*r<<endl;
}
return ;
}

代码

POJ 2185 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 Limit: 65536K Total Submissions: 8226   Accepted: 3549 Desc ...

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

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

  4. POJ 2185 Milking Grid(KMP最小循环节)

    http://poj.org/problem?id=2185 题意: 给出一个r行c列的字符矩阵,求最小的覆盖矩阵可以将原矩阵覆盖,覆盖矩阵不必全用完. 思路: 我对于字符串的最小循环节是这么理解的: ...

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

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

  6. POJ 2185 Milking Grid(KMP)

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

  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 2165 Milking Grid(kmp)

    Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, ...

随机推荐

  1. Android SDK安装教程

    1.下载安装JDK(java 开发套件),天空软件站下载http://www.skycn.com/soft/3116.html(或 到java官网下载),下载后双击安装即可. 2.下载android ...

  2. MapReduce使用JobControl管理实例

    import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.fs.Path; impo ...

  3. 0day漏洞是什么意思啊?

    在报纸上看到xx又爆出0day漏洞是什么意思? day漏洞,是已经发现但是官方还没发布补丁的漏洞. 信息安全意义上的0Day是指在安全补丁发布前而被了解和掌握的漏洞信息. http://baike.b ...

  4. 分页控件-ASP.NET(AspNetPager)

    AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: <div class="oa-el ...

  5. 微信开发学习日记(八):7步看懂weiphp插件机制,核心目标是响应微信请求

    又经过了几个小时的梳理.回顾,截至目前,终于对weiphp这个框架的机制搞明白了些.想要完全明白,自然还需要大把的时间.第1步:   配置微信公众号,http://weiphp.jiutianniao ...

  6. 《ASP.NET1200例》实现投票的用户控件

    用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...

  7. Apache配置文件中的deny和allow的使用

    Apache配置文件中的deny和allow的使用 由于产品的需要,最近在配置apache的负载均衡功能,但是在配置虚拟主机的访问权限的时候我们遇到了一些问题.主要问题是deny和allow的执行顺序 ...

  8. 解决ecshop登陆自动退出的莫名现象

    最近在做ecshop的二次开发,程序发布后测试出现一个莫名的问题.点击几次页面后出现session丢失,需要重复登陆:本地怎么测试也都无法重现问题.一开始以为是修改程序的问题,可是怎么找都找不着问题所 ...

  9. javascript onload队列

    2014年10月29日 10:40:14 function addLoadEvent(func){ var oldonload = window.onload; if (typeof window.o ...

  10. MPlayer-ww 增加边看边剪切功能+生成高质量GIF功能

    http://pan.baidu.com/s/1eQm5a74 下载FFmpeg palettegen paletteuse documentation 需要下载 FFmpeg2.6 以上 并FFmp ...