AC日记——Milking Grid poj 2185
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 8314 | Accepted: 3586 |
Description
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.
Input
* 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.
Output
Sample Input
2 5
ABABA
ABABA
Sample Output
2
Hint
Source
#include <cstdio>
#include <cstring>
#include <iostream> #define che 39
#define mod 100000009LL
#define mod1 100000007LL
#define mod2 13000007LL using namespace std; int next[],next_[],r,c,ans; long long t[],p[]; char ch[]; int main()
{
while(scanf("%d%d",&r,&c)==)
{
memset(t,,sizeof(t));
memset(p,,sizeof(p));
memset(next,,sizeof(next));
memset(next_,,sizeof(next_));
for(int i=;i<=r;i++)
{
cin>>ch;
for(int j=;j<c;j++)
{
t[j+]=((t[j+]*che)%mod+((ch[j]-'')*che))%mod1;
p[i]=((p[i]*che)%mod+((ch[j]-'')*che))%mod2;
}
}
int i=,j=;next[]=-;
while(j<=c)
{
if(i==||t[i]==t[j]) next[j++]=i++;
else i=next[i-]+;
}
i=,j=,next_[]=-;
while(j<=r)
{
if(i==||p[i]==p[j]) next_[j++]=i++;
else i=next_[i-]+;
}
ans=(c-next[c])*(r-next_[r]);
cout<<ans;
putchar('\n');
}
return ;
}
AC日记——Milking Grid poj 2185的更多相关文章
- Milking Grid POJ - 2185 || 最小覆盖子串
Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时 ...
- AC日记——K-th Number poj 2104
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 52348 Accepted: 17985 Ca ...
- AC日记——Housewife Wind poj 2763
Language: Default Housewife Wind Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 10525 ...
- AC日记——Sliding Window poj 2823
2823 思路: 单调队列: 以前遇到都是用线段树水过: 现在为了优化dp不得不学习单调队列了: 代码: #include <cstdio> #include <cstring> ...
- Milking Grid poj2185
Milking Grid POJ - 2185 时限: 3000MS 内存: 65536KB 64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Eve ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
随机推荐
- (74)zabbix第三方认证之http(nginx basic auth)
HTTP Basic Auth认证方式,我们将在实例中使用nginx来演示,Apache也类似. zabbix认证配置 Administration>> Authentication,将h ...
- Python + Bottle + 谷歌搜索Api 实现简单搜索引擎
1.运行环境 python3 centos7 2.Bottle的使用 使用bottle主要是因为它仅用python自带的库即可实现对web的搭建. bottle源码分析 bottle使用教程 3.代码 ...
- 如何编写自己的C语言头文件
一些初学C语言的人,不知道头文件(*.h文件)原来还可以自己写的.只知道调用系统库函数时,要使用#include语句将某些头文件包含进去.其实,头文件跟.C文件一样,是可以自己写的.头文件是一种文本文 ...
- OpenCV中图像的读取,显示与保存
图像的读取,显示与保存 相关函数:cv2.imread().cv2.imshow().cv2.imwrite() 1.读入图像: 用cv2.imread()函数来读取图像,cv2.imread(路 ...
- 使用nohup+& 踩到的坑
首先分清楚nohup与&: &是指在后台运行一般在执行命令后,都会显式的在前台执行,当Ctrl+C后进程回宕掉,但是 在命令后加&,即使Ctrl+C,程序还在进行,但是,当关闭 ...
- 并查集:POJ1182-食物链(并查集比较高端的应用)
食物链 Time Limit: 1000MS Memory Limit: 10000K Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C ...
- Linux: 正则表达式
正则表达式:正规的表示法,常规的表示法(Regular Expression)正则表达式使用单个字符串来描述,匹配一系列的符合某个句发规则的字符串. 1)命令格式; grep [正则] 字符串 文件 ...
- selenium2设置浏览器窗口
1.窗口最大化 //设置窗口最大化driver.manage().window().maximize(); 2.指定设置窗口大小 //指定呀设置窗口的宽度为:800,高度为600Dimension d ...
- UVa 1366 DP Martian Mining
网上的题解几乎都是一样的: d(i, j, 0)表示前i行前j列,第(i, j)个格子向左运输能得到的最大值. d(i, j, 1)是第(i, j)个格子向上运输能得到的最大值. 但是有一个很关键的问 ...
- loj2000 「SDOI2017」数字表格
there #include <iostream> #include <cstring> #include <cstdio> using namespace std ...