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 ...
随机推荐
- C# datatable 导出到Excel
datatable导出到Excel /// <summary> /// 将DataTable导出为Excel文件(.xls) /// </summary> /// <pa ...
- Mac015--在Mac下安装使用Vagrant
网址:http://yansu.org/2014/04/10/install-vagrant-in-mac.html 一.安装Vagrant 下载地址在http://www.vagrantup.com ...
- c++中关于类的长度的猜想
在无意中,我偶然发现了类的长度并不是由函数的类型及个数决定,也并非是2的倍数.4的倍数. 在翻阅资料中,我得出了一些我认为可能的猜想. 我们先来看一串代码 #include<iostream&g ...
- sql下的xml配置文件中特殊使用的sql语句编写
1.使用服用的sql语句------------查询学生表所有字段 <sql id="selectAllStuAll"> select stu.id,stu.name, ...
- Java学习day11-类的成员之三:构造器(构造方法)
一.构造器(构造方法) 语法格式: 修饰符 类名(参数列表){ 初始化语句: } 构造器的特征: 1.它具有与类相同的名称 2.它不声明返回值类型.(与声明为void不同) 3.不能被static.f ...
- 打乱一个排好序的 list 对象 alist?
1. import random 2. random.shuffle(alist)
- HDU 4285 circuits( 插头dp , k回路 )
circuits Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Dynamic Mapping和常见字段类型
原文:Dynamic Mapping和常见字段类型 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn. ...
- Ubuntu 安装 ansible
sudo apt update sudo apt-get install software-properties-common sudo apt-add-repository --yes ppa:an ...
- vue.js(14)--自定义全局指令
<input type="text" class="form-control" v-model="keywords" v-focus& ...