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 ...
随机推荐
- js 创建对象的方法
<script> //1.字面量语法 var rectangle1 = {}; rectangle1.name="mindong"; rectangle1.width ...
- 解决旋转屏幕闪退在androidManifest.template.xml里,activity项添加:
解决旋转屏幕闪退在androidManifest.template.xml里,activity项添加:android:configChanges="orientation|keyboard ...
- 20190925 On Java8 第二十二章 枚举
第二十二章 枚举 基本 enum 特性 创建 enum 时,编译器会为你生成一个相关的类,这个类继承自 Java.lang.Enum. valueOf() 是在 Enum 中定义的 static 方法 ...
- IIS中配置Office COM组件 [dufu图解系列]
解决问题: 读写office文档目前有2中方法,一种为引用微软的office com组件(下图为Microsoft Office 16.0 Object Library), 另一种为用第三方组件NPO ...
- Python3数据分析与挖掘建模实战 学习 教程
Python3数据分析与挖掘建模实战 学习 教程 Python数据分析简介Python入门 运行:cmd下"python hello.py" 基本命令: 第三方库安装Windows ...
- [Python3 练习] 001 温度转换1
题目:温度转换 I (1) 描述 温度的刻画有两个不同体系:摄氏度 (Celsius) 和华氏度 (Fabrenheit) 请编写程序将用户输入的华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度 转换 ...
- [APIO2019] [LOJ 3146] 路灯 (cdq分治或树状数组套线段树)
[APIO2019] [LOJ 3146] 路灯 (cdq分治或树状数组套线段树) 题面 略 分析 首先把一组询问(x,y)看成二维平面上的一个点,我们想办法用数据结构维护这个二维平面(注意根据题意这 ...
- latex如何给表格添加注释
在latex中,想给表格添加注释,可以使用threeparttable这个包 代码如下: \usepackage{threeparttable} \begin{table*} \begin{three ...
- Docker备份镜像
docker save -o mycentos.tar mycentos_new:1.1 指定输出到的文件 执行后,运行 ls 命令即可看到打成的tar包, 因为有463M所以打包要一会
- CF 82 D.Two out of Three
前言 全网唯一不同题解 设 \(f[i][j]\) 表示第 \(i\) 次选取留下来的数是 \(k\) 的最小花费 枚举前面的留下来的点 \(k\) 当前能留下的点只有 \((2*i),(2*i+1) ...