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 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
随机推荐
- 浅谈 MySQL 中优化 SQL 语句查询常用的 30 种方法
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索 ...
- java中类与对象的概念(2013-05-04-bd 写的日志迁移
1:类是抽象的,概念的,代表一类事物,比如人类.猫类.. 2:对象是具体的,实际的,代表一个具体的事物 3:类是对象的模板,对象是类的一个个体,实例 创建对象的两种方法: 1.先声明在创建 对象声明: ...
- vim中,在编辑模式下如何快速移动光标
编辑 ~/.vimrc 配置文件,加入如下行,编辑模式下自定义的快捷键 inoremap <C-o> <Esc>o inoremap <C-l> <Righ ...
- 线段树、前缀数组:HDU1591-Color the ball(区间更新、简单题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 带权并查集:CF-2015 ACM Arabella Collegiate Programming Contest(F题)
F. Palindrome Problem Description A string is palindrome if it can be read the same way in either di ...
- Leetcode 559. N叉树的最大深度
题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...
- BZOJ 4479: [Jsoi2013]吃货jyy
一句话题意:求必须包含某K条边的回路(回到1),使得总权值最小 转化为权值最小的联通的偶点 令F[i]表示联通状态为i的最小权值,(3^n状压)表示不在联通块内/奇点/偶点,连边时先不考虑必选的边的度 ...
- BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站
难度在于读题 #include<cstdio> #include<algorithm> #include<queue> using namespace std; p ...
- tar.xz结尾的文件的解压缩方法
例如: codeblocks-13.12-1_i386.debian.stable.tar 这个压缩包也是两层压缩,外面是xz压缩方式,里层是tar压缩方式. 解压缩方法: $xz -d ***.ta ...
- Leetcode31--->Next Permutation(数字的下一个排列)
题目: 给定一个整数,存放在数组中,求出该整数的下一个排列(字典顺序):要求原地置换,且不能分配额外的内存 举例: 1,2,3 → 1,3,2: 3,2,1 → 1,2,3: 1,1,5 → 1, ...