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 ...
随机推荐
- 百度人脸识别python调用例子
# 首先pip install baidu-aip # SDK文档链接http://ai.baidu.com/docs#/Face-Python-SDK/top import base64 from ...
- docker远程访问TLS证书认证shell
docker开启远程访问端口,防止非法访问 配置证书认证 配置防火墙或安全策略 #!/bin/bash # docker.tls.sh # 环境centos 7 ,root # 创建 Docker T ...
- 应用安全 - 软件漏洞 - Jira漏洞汇总
CVE-2019-8451 ssrf url = url + '/plugins/servlet/gadgets/makeRequest?url=' + host + '@www.baidu.com/ ...
- debian下重装mysql
mysql总是报错,说sock文件不存在,网上若干方法,更改权限,更改配置文件,结果还是不能正常生成.sock文件.没办法,删除,重新安装. 完全删除: 删除 mysqlsudo apt-get au ...
- python基础-2 编码转换 pycharm 配置 运算符 基本数据类型int str list tupple dict for循环 enumerate序列方法 range和xrange
1.编码转换 unicode 可以编译成 UTF-U GBK 即 #!/usr/bin/env python # -*- coding:utf-8 -*- a = '测试字符' #默认是utf-8 a ...
- 手把手教你用Pytorch-Transformers——部分源码解读及相关说明(一)
一.简介 Transformers是一个用于自然语言处理(NLP)的Python第三方库,实现Bert.GPT-2和XLNET等比较新的模型,支持TensorFlow和PyTorch.本文介对这个库进 ...
- Python内建函数reduce()用法
reduce把一个函数作用在一个序列[x1, x2, x3...]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算,下面讲述Python内建函数reduce()用法. ...
- AppDomain (转)
AppDomain是CLR的运行单元,它可以加载Assembly.创建对象以及执行程序.AppDomain是CLR实现代码隔离的基本机制. 每一个AppDomain可以单独运行.停止:每个AppDom ...
- jQuery——复选框操作
学习jQuer对表单.表格操作的过程中,按照书上的例子发现一个问题: <!DOCTYPE html> <html> <head> <title>复选框应 ...
- webpack打包过程及开发过程
1.传统: 1)分模块去定义js.js中要导出将来要被打包的方法module.exports 2)定义main.js入口文件(主文件).在此文件中,导入引用的js文件 var {add} = requ ...