传送门

直接转田神的了:

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 5
ABABA
ABABA

Sample Output

2

Hint

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

Source

USACO 2003 Fall

题目链接:http://poj.org/problem?id=2185

题目大意:给你一个r行c列的字符矩阵,令其一个子矩阵,使得这个子矩阵无限复制成的大矩阵包含原矩阵,现求这个子矩阵的最小尺寸

题目分析:1.把每行字符串看作一个整体对行求next数组
                  2.将矩阵转置
                  3.进行操作1,注意这里的行是原来的列,列是原来的行,相当于求原来列的next数组
                  4.求出len-next[len]即最小不重复子串的长度作为子矩形的边长

13892851 njczy2010 2185 Accepted 42452K 79MS G++ 1707B 2015-02-16 10:51:05
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100
#define M 10005
//#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
//#define inf 2147483647
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,m;
char s[M][M];
char c[M][M];
int nexts[M];
int nextc[M];
int l;
int now; void get_nexts()
{
int i,j;
i=;j=-;nexts[]=-;
while(i<n)
{
if(j==- || strcmp(s[i],s[j])==){
i++;j++;nexts[i]=j;
}
else{
j=nexts[j];
}
}
} void get_nextc()
{
int i,j;
i=;j=-;nextc[]=-;
while(i<m)
{
if(j==- || strcmp(c[i],c[j])==){
i++;j++;nextc[i]=j;
}
else{
j=nextc[j];
}
}
} void ini()
{
int i,j;
for(i=;i<n;i++){
scanf("%s",s[i]);
}
for(j=;j<m;j++){
for(i=;i<n;i++){
c[j][i]=s[i][j];
}
c[j][i]='\0';
}
} void solve()
{
get_nexts();
get_nextc();
} void out()
{
printf("%d\n",(n-nexts[n])*(m-nextc[m]));
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%d%d",&n,&m)!=EOF)
{
ini();
solve();
out();
}
return ;
}

POJ 2185 Milking Grid [二维KMP next数组]的更多相关文章

  1. Match:Milking Grid(二维KMP算法)(POJ 2185)

    奶牛矩阵 题目大意:给定一个矩阵,要你找到一个最小的矩阵,这个矩阵的无限扩充的矩阵包含着原来的矩阵 思路:乍一看这一题确实很那做,因为我们不知道最小矩阵的位置,但是仔细一想,如果我们能把矩阵都放在左上 ...

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

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

  3. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  4. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  5. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  6. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  7. POJ 2155 Matrix 【二维树状数组】(二维单点查询经典题)

    <题目链接> 题目大意: 给出一个初始值全为0的矩阵,对其进行两个操作. 1.给出一个子矩阵的左上角和右上角坐标,这两个坐标所代表的矩阵内0变成1,1变成0. 2.查询某个坐标的点的值. ...

  8. POJ 2155 Matrix (二维树状数组)题解

    思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...

  9. POJ 2155:Matrix 二维树状数组

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 21757   Accepted: 8141 Descripti ...

随机推荐

  1. 树形DP 统计树中长度为K的路径数量——Distance in Tree

    一.问题描述 给出一棵n个节点的树,统计树中长度为k的路径的条数(1<=n<=50000 , 1<=k<=500). 二.解题思路 设d[i][k]表示以i为根节点长度为k的路 ...

  2. history 路由且带二级目录的Apache配置

    有多个项目目录的时候 由于项目不知一个,所以不得不为每一个项目建一个专有的文件夹,这就导致了在配置nginx的时候会出现二级目录   - step1: 修改 vue.config.js   添加配置 ...

  3. WPF知识点全攻略07- 数据绑定(Binding)

    数据绑定是WPF不得不提,不得不会系列之一 数据绑定简言之,就是把数据源的数据绑定到目标对象的属性上.目标对象可以是承自DependencyProperty的任何可访问的属性或控件,目标属性必须为依赖 ...

  4. java面试基础篇(三)

    1.Q:ArrayList 和 LinkedList 有什么区别? A:ArrayList查询快!LinkedList增删快.ArrayList是基于索引的数据接口,它的底层是数组.空间占用相对小一些 ...

  5. EF关于报错Self referencing loop detected with type的原因以及解决办法

    1)具体报错 { "Message": "出现错误.", "ExceptionMessage": "“ObjectContent` ...

  6. Codeforces 1012A Photo of The Sky

    作为一个蒟蒻,\(\tt{CF}\)止步\(Div.2\;C\) 这个题主要考察思维,正解代码炒鸡短-- 以下大部分搬运自官方题解 题目大意: 给你一段长度为\(2n\)的数列,将这个数列分为两个可重 ...

  7. 相机 感光度iso,焦距,光圈,ccd 和 噪点, 景深关系表格

    表格 矩阵 感官度iso: 越低曝光速度越慢,所谓慢工出细活,成像质量会好,如果形成的话. 但是因为慢,所以要更多的光量,才能画完. 就需要更慢的快门 (但是太慢手抖的话就糊掉,或者动的物体形成轨迹. ...

  8. 解读tensorflow之rnn【转】

    转自:https://blog.csdn.net/mydear_11000/article/details/52414342 from: http://lan2720.github.io/2016/0 ...

  9. luogu2312 解方程 (数论,hash)

    luogu2312 解方程 (数论,hash) 第一次外出学习讲过的题目,然后被讲课人的一番话惊呆了. 这个题,我想着当年全国只有十几个满分.....然后他又说了句我考场A这道题时,用了5个模数 确实 ...

  10. [LUOGU] P1908 逆序对

    题目描述 猫猫TOM和小老鼠JERRY最近又较量上了,但是毕竟都是成年人,他们已经不喜欢再玩那种你追我赶的游戏,现在他们喜欢玩统计.最近,TOM老猫查阅到一个人类称之为"逆序对"的 ...