Milking Grid poj2185
| 时限: 3000MS | 内存: 65536KB | 64位IO格式: %I64d & %I64u | 
问题描述
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.
输入
* 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.
输出
样例输入
2 5
ABABA
ABABA
样例输出
2
提示
来源
#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的更多相关文章
- 【POJ2185】【KMP + HASH】Milking Grid
		
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
 - poj2185 Milking Grid【KMP】
		
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10084 Accepted: 4371 Des ...
 - POJ2185 Milking Grid 【lcm】【KMP】
		
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
 - CH1808 Milking Grid
		
题意 POJ2185 数据加强版 描述 Every morning when they are milked, the Farmer John's cows form a rectangular gr ...
 - POJ 2185  Milking Grid KMP(矩阵循环节)
		
Milking Grid Time Limit: 3000MS Memory Lim ...
 - POJ 2185 Milking Grid(KMP)
		
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
 - POJ 2185 Milking Grid [KMP]
		
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8226 Accepted: 3549 Desc ...
 - poj 2185  Milking Grid
		
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
 - AC日记——Milking Grid poj 2185
		
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8314 Accepted: 3586 Desc ...
 
随机推荐
- Prometheus Alertmanager Grafana 监控警报
			
Prometheus Alertmanager Grafana 监控警报 #node-exporter, Linux系统信息采集组件 #prometheus , 抓取.储存监控数据,供查询指标 #al ...
 - 剑指offer(1):数组
			
1 写作计划 最近在看<剑指offer>,发现自己有很多的数据结构与算法的基础知识要复习,<好书一起读(131):让写作更好>中提到用写作倒逼阅读,我很是赞同.所以,计划以&l ...
 - Jenkins持续集成_03_添加测试报告
			
前言 Jenkins持续集成自动化测试项目后,可以在控制台输出中查看测试结果,但是这样排查起来往往不够直观.为了更直观的查看测试结果,可以在Jenkins上展示测试报告.测试报告中测试结果情况展示的更 ...
 - vue-router路由详细
			
由于Vue在开发时对路由支持的不足,于是官方补充了vue-router插件.vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来.传统的页面应用,是用一些超链接来实现 ...
 - 第五周总结&第三次实验报告
			
实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 1.已知字符串:"this is a test of java".按要求执 ...
 - LaTex中集合关系的表示
			
集合的大括号: \{ ... \} \(\{ ... \}\) 集合中的"|": \mid \(\mid\) 属于: \in \(\in\) 不属于: \not\in \(\not ...
 - [Markdown] 01 简单应用 第一弹
			
目录 0. "调用函数前必先声明" 0.1 Table of Content 0.2 分割线 0.3 引用 0.4 标记 0.5 关于 html 0.6 代码块 用法 1 用法 2 ...
 - jsp常问面试题集
			
1.Servlet总结 在Java Web程序中,Servlet主要负责接收用户请求 HttpServletRequest,在doGet(),doPost()中做相应的处理,并将回应HttpServl ...
 - vue 跳转页面返回时tab状态有误的解决办法
			
一.前言 最近在做新vue项目的时候遇到了一个问题,就是tab间的切换没有问题,当跳转到其他页面时,且这个页面并非子路由,再用浏览器的返回按钮返回首页时,tab的active始终指向默认的第一个选项. ...
 - [AtCoder ARC076] F Exhausted?
			
霍尔定理 + 线段树? 咱学学霍尔定理... 霍尔定理和二分图完美匹配有关,具体而言,就是定义了二分图存在完美匹配的充要条件: 不妨设当前二分图左端集合为 X ,右端集合为 Y ,X 与 Y 之间的边 ...