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 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
随机推荐
- 201621123080《Java程序设计》第十一周学习总结
201621123080<Java程序设计>第十一周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 ...
- LNMP一键安装包开启pathinfo和rewrite模式
此教程适用于集成安装包lnmp,官网是https://lnmp.org/ 一. 开启pathinfo #注释 下面这一行 #include enable-php.conf #载入新的配置文件 incl ...
- mac Parallels Desttop 13 win7/win8 无法连接网络
把 “源” 从共享网络改为"Wi-Fi" 在mac 这边点击菜单栏windows图标,选配置(如果没有配置,点控制中心,在点控制中心的齿轮,)选 硬件 找到网络 解锁,上边第一行就 ...
- python入门:数字型和字符串换行要同类型 注意连接符
#!/usr/bin/env python # -*- coding: utf-8 -*- #数字型和字符串换行要同类型 注意连接符 a = 1 b = 2 print(str(a) + " ...
- php 计算当天凌晨时间戳 以及获取其他常用时间戳
php 计算当日凌晨时间戳 以及获取其他常用时间戳(持续补充中...) 获取当天凌晨时间戳: echo strtotime(date('Y-m-d')); 以下再列举一些获取其他常用时间戳的方法 获取 ...
- Pyhon从入门到致命
第一章 基础 1.python2和python3的区别 2.数据类型 2.1 int 整型 2.2 str 字符串不可变类型 2.3 bool 布尔类型 2.4 list 列表 2.5 tuple 元 ...
- Stall Reservations POJ - 3190 (贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11002 Accepted: 38 ...
- ghost模板总结
ghost模板的二次开发相对容易,附文档: http://themes.ghost.org/v0.6.0/docs/meta_title 这里有各行变量的说明. {{#is "home&qu ...
- 用Python表达对Android的想法
组员:喻航,张子东 视频:点我 #DISCARD ANDROID TODAY! import turtle import turtle as gui #setting turtle.screensiz ...
- POJ 1609 Tiling Up Blocks
Tiling Up Blocks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4675 Accepted: 1824 ...