Milking Grid

POJ - 2185
时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u

提交 状态

已开启划词翻译

问题描述

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.

输入

* 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.

输出

* Line 1: The area of the smallest unit from which the grid is formed 

样例输入

2 5
ABABA
ABABA

样例输出

2

提示

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

来源

kmp延伸……你是猪么
 
做两次KMP
行和列分别是len-next[len];
最后两个结果相乘就可以了
 
本题只是把线性变成平面,kmp对字符的操作变成字符串……
 
 #include<iostream>
#include<cstdio>
#include<cstring> using namespace std; #define maxn 1000008 char s[maxn][];
int r, c, next[maxn]; bool same1(int i, int j) // 判断第i行和第j行是否相等
{
for(int k = ; k < c; k++)
if(s[i][k] != s[j][k])
return false;
return true;
} bool same2(int i, int j) // 判断第i列和第j列是否相等。
{
for(int k = ; k < r; k++)
if(s[k][i] != s[k][j])
return false;
return true;
} int main()
{
while(~scanf("%d%d", &r, &c))
{
for(int i = ; i < r; i++)
scanf("%s", s[i]);
int j, k;
memset(next, , sizeof(next));
j = ;
k = next[] = -;
while(j < r)
{
while(- != k && !same1(j, k))
k = next[k];
next[++j] = ++k;
}
int ans1 = r - next[r]; // r-next[r]就是需要的最短的长度可以覆盖这个平面
memset(next, , sizeof(next));
j = ;
k = next[] = -;
while(j < c)
{
while(- != k && !same2(j, k))
k = next[k];
next[++j] = ++k;
}
int ans2 = c - next[c]; //列的 printf("%d\n", ans1*ans2);
}
return ;
}
 
 

Milking Grid poj2185的更多相关文章

  1. 【POJ2185】【KMP + HASH】Milking Grid

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

  2. poj2185 Milking Grid【KMP】

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10084   Accepted: 4371 Des ...

  3. POJ2185 Milking Grid 【lcm】【KMP】

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

  4. CH1808 Milking Grid

    题意 POJ2185 数据加强版 描述 Every morning when they are milked, the Farmer John's cows form a rectangular gr ...

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

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

  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]

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

  8. poj 2185 Milking Grid

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

  9. AC日记——Milking Grid poj 2185

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8314   Accepted: 3586 Desc ...

随机推荐

  1. css 实现渐变

    background:-ms-radial-gradient(circle,rgba(0, 0, 0, 0.2),rgba(0,0,0,0)); /* IE 10*/ background: -web ...

  2. django在线教育网站开发---需求分析

    开发目录: django app设计 user model.py 编写 courses models.py 编写 -Course 课程基本信息 -Lesson 章节信息 -Video -视频 -Cou ...

  3. Node.js实战13:fs模块奥义!开发一个数据库。

    本文,将使用fs开发一种简单的文件型数据库. 数据库中,记录将采用JSON模式,内容型如: {"key":"a","value":" ...

  4. css的继承之width属性(容易忽略)

    众所周知,css的三大特性分别是 继承性,层叠性,和优先级. 那么这里就详细说一下css中width的继承性及其特殊情况. 继承性概念详解:css的继承性指的被包在内部的标签拥有外部标签的样式性,子元 ...

  5. Codeforces 396C (DFS序+线段树)

    题面 传送门 题目大意: 给定一棵树,每个点都有权值,边的长度均为1,有两种操作 操作1:将节点u的值增加x,并且对于u的子树中的任意一个点v,将它的值增加x-dist(u,v)*k, dist(u, ...

  6. make: *** 没有指明目标并且找不到 makefile

    make: *** 没有指明目标并且找不到 makefile. 停止. make: *** 没有规则可以创建目标“install”. 停止.   不是没有makefile文件,而是你没有安装gcc编译 ...

  7. 8、神经网络:表述(Neural Networks: Representation)

    8.1 非线性假设 我们之前学的,无论是线性回归还是逻辑回归都有这样一个缺点,即:当特征太多时,计算的负荷会非常大. 下面是一个例子: 当我们使用x1, x2 的多次项式进行预测时,我们可以应用的很好 ...

  8. python内置函数sorted()及sort() 函数用法和区别

    python内置函数sorted(),sort()都有排序的意思,但是两者有本质的区别,sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作,list 的 sort ...

  9. 回溯---N皇后

    N 皇后 51. N-Queens (Hard) 题目描述:   在n*n的矩阵中摆放n个皇后,并且每个皇后不能在同一列,同一个对角线上,求所有的n皇后解. 思路分析:   一行一行地摆放,在确定一行 ...

  10. 行人重识别(ReID) ——数据集描述 DukeMTMC-reID

    数据集简介 DukeMTMC 数据集是一个大规模标记的多目标多摄像机行人跟踪数据集.它提供了一个由 8 个同步摄像机记录的新型大型高清视频数据集,具有 7,000 多个单摄像机轨迹和超过 2,700 ...