Milking Grid poj2185
Milking Grid
时限: 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
提示
来源
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 5 using namespace std; 6 7 #define maxn 1000008 8 9 char s[maxn][80]; 10 int r, c, next[maxn]; 11 12 bool same1(int i, int j) // 判断第i行和第j行是否相等 13 { 14 for(int k = 0; k < c; k++) 15 if(s[i][k] != s[j][k]) 16 return false; 17 return true; 18 } 19 20 bool same2(int i, int j) // 判断第i列和第j列是否相等。 21 { 22 for(int k = 0; k < r; k++) 23 if(s[k][i] != s[k][j]) 24 return false; 25 return true; 26 } 27 28 int main() 29 { 30 while(~scanf("%d%d", &r, &c)) 31 { 32 for(int i = 0; i < r; i++) 33 scanf("%s", s[i]); 34 int j, k; 35 memset(next, 0, sizeof(next)); 36 j = 0; 37 k = next[0] = -1; 38 while(j < r) 39 { 40 while(-1 != k && !same1(j, k)) 41 k = next[k]; 42 next[++j] = ++k; 43 } 44 int ans1 = r - next[r]; // r-next[r]就是需要的最短的长度可以覆盖这个平面 45 memset(next, 0, sizeof(next)); 46 j = 0; 47 k = next[0] = -1; 48 while(j < c) 49 { 50 while(-1 != k && !same2(j, k)) 51 k = next[k]; 52 next[++j] = ++k; 53 } 54 int ans2 = c - next[c]; //列的 55 56 printf("%d\n", ans1*ans2); 57 } 58 return 0; 59 }
转载于:https://www.cnblogs.com/Tinamei/p/4803094.html
Milking Grid poj2185相关推荐
- POJ 2185 Milking Grid (KMP,GCD)
http://poj.org/problem?id=2185 求最小覆盖子矩阵的面积,求出每行的最小覆盖子串,求最小公倍数,就是矩阵的长度 求出每列的最小覆盖子矩阵然后求最小公倍数,就是矩阵的宽 最小 ...
- linux6查看用户密码,linux如何查看所有的用户(user)、用户组(group)、密码(password/passwd)...
linux如何查看所有的用户和组信息_百度经验 https://jingyan.baidu.com/article/a681b0de159b093b184346a7.html linux添加用户.用户 ...
- POJ的题目分类(两个版本)
版本一: 简单题 1000A+B Problem 1001Exponentiation 1003 Hangover 1004 Financial Management 1005 I Think I N ...
- POJ前面的题目算法思路【转】
1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...
- POJ 超详细分类
POJ 各题算法 1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 ...
- 使用NVIDIA GRID vPC支持视频会议和算力工具
使用NVIDIA GRID vPC支持视频会议和算力工具 随着2020年的发展,远程工作解决方案已成为许多人的新常态.企业正在寻找行之有效的解决方案,如虚拟桌面基础设施(VDI),以使他们的团队能够在 ...
- CSS grid 的用法
grid 的用法 加三个宽度为 200px 的列. .container {display: grid;grid-template-columns: 200px 200px 200px; } 用 fr ...
最新文章
- javascript的知识总结
- matlab数据无量纲化_MATLAB数据预处理——归一化和标准化
- 如何写sybase sql脚本文件_写一个删除lock文件的skill脚本
- 解一元二次方程的C++实现
- tensorflow tf.matmul() (多维)矩阵相乘(多维矩阵乘法)
- GDCM:检测SIEMENS JPEG无损压缩图像的测试程序
- LogMiner学习笔记
- 搜索——Red and Black(hdu1312)
- 算法导论 第十三章 红黑树(python)-1插入
- teamviewer设备数量上限怎么解决_会议音响设备出现啸叫怎么办?不要担心,这3个方法帮你解决...
- 【链表】剑指offer:从尾到头打印链表
- 全才出书,值得一读——Leo推荐《我也能做CTO之程序员职业规划》
- OpenCV46:立体图像的深度图|Depth Map
- Mac 终端命令自动补齐的办法
- 2020-10-28-Requests及爬虫清单
- dedecms教程:龙书浩最新DedeCmsV5.7建站仿站VIP视频教程免费下载
- encode()和decode()编码与解码的解析、常用编码与为何要encode和decode
- 851-40亿个号码如何去重?
- Github上开源项目readme里好看的高大上的有趣的徽章从何而来
- 1018 锤子剪刀布python3无超时