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 ;
}
 
 

最新文章

  1. SQLServer2000数据库的安装
  2. RadioButtonFor绑定值
  3. M2: XAML Controls(2)
  4. Java Web项目调优原则
  5. Test Android with QTP
  6. JavaScript自定义右键菜单
  7. 简单的JS运动封装实例---侧栏分享到
  8. port-channel和channel-group
  9. 浅析JavaScript引用类型之--Object、Array
  10. oracle12c:通过oracle客户端工具配置tns,并使用sqlldr进行批量导入数据
  11. Asp.Net Core&amp;Jenkins持续交付到Windows Server
  12. python下彻底解决浏览器多标签打开与切换问题
  13. Mosaic 前端微服务框架
  14. 由于想要实现下载的文件可以进行选择,而不是通过&lt;a&gt;标签写死下载文件的参数,所以一直想要使用JFinal结合ajax实现文件下载,但是ajax实现的文件下载并不能触发浏览器的下载文件弹出框,这里通过模拟表单提交实现同样的效果。
  15. Drools实战系列(三)之eclipse创建工程
  16. Finalize和Dispose的区别
  17. 回顾经典问题算法:LIS, LCS-(DP类别)
  18. 001 KNN分类 最邻近算法
  19. [译文]casperjs 的API-casper模块
  20. 007 Android 单击事件、toast使用

热门文章

  1. python+selenium的WebElement对象操作
  2. 医院里的CR、DR、CT、磁共振、B超都是什么?
  3. c3p0连接池快速入门
  4. Ant-编译构建(2)-第3方jar包引入、log4j2
  5. mysql远程命令连接
  6. BZOJ 1875(DP+矩阵快速幂)
  7. 大神级回答exists与in的区别
  8. python学习笔记(7)容器以及容器的访问使用
  9. Sql Server 2008安装时提示重启计算机失败解决办法
  10. PgSQL · 特性分析 · PG主备流复制机制