Milking Grid
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 8314   Accepted: 3586

Description

Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns.

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

* Line 1: Two space-separated integers: R and C

* 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

* Line 1: The area of the smallest unit from which the grid is formed 

Sample Input

2 5
ABABA
ABABA

Sample Output

2

Hint

The entire milking grid can be constructed from repetitions of the pattern 'AB'.

Source

 
 
思路:
  每一列都给hash成一个值,然后横着kmp,找到最小循环节长度l1;
  每一行都给hash成一个值,然后竖着kmp,找到最小循环节长度l2;
  然后输出l1*l2;
  劳资re十多次,才发现题目里面是多组数据;
  然后又re十多次,看discuss才知道r和c的范围弄反了;
  气人简直、、、
 
 
来,上代码:

#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的更多相关文章

  1. Milking Grid POJ - 2185 || 最小覆盖子串

    Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时 ...

  2. AC日记——K-th Number poj 2104

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 52348   Accepted: 17985 Ca ...

  3. AC日记——Housewife Wind poj 2763

    Language: Default Housewife Wind Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10525 ...

  4. AC日记——Sliding Window poj 2823

    2823 思路: 单调队列: 以前遇到都是用线段树水过: 现在为了优化dp不得不学习单调队列了: 代码: #include <cstdio> #include <cstring> ...

  5. Milking Grid poj2185

    Milking Grid POJ - 2185 时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Eve ...

  6. poj 2185 Milking Grid

    Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS   Memory Limit: 65536K       Descript ...

  7. POJ 2185 Milking Grid [二维KMP next数组]

    传送门 直接转田神的了: Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6665   Accept ...

  8. [poj 2185] Milking Grid 解题报告(KMP+最小循环节)

    题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...

  9. POJ 2185 Milking Grid KMP循环节周期

    题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...

随机推荐

  1. 201621123080《Java程序设计》第十一周学习总结

    201621123080<Java程序设计>第十一周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 ...

  2. LNMP一键安装包开启pathinfo和rewrite模式

    此教程适用于集成安装包lnmp,官网是https://lnmp.org/ 一. 开启pathinfo #注释 下面这一行 #include enable-php.conf #载入新的配置文件 incl ...

  3. mac Parallels Desttop 13 win7/win8 无法连接网络

    把 “源” 从共享网络改为"Wi-Fi" 在mac 这边点击菜单栏windows图标,选配置(如果没有配置,点控制中心,在点控制中心的齿轮,)选 硬件 找到网络 解锁,上边第一行就 ...

  4. python入门:数字型和字符串换行要同类型 注意连接符

    #!/usr/bin/env python # -*- coding: utf-8 -*- #数字型和字符串换行要同类型 注意连接符 a = 1 b = 2 print(str(a) + " ...

  5. php 计算当天凌晨时间戳 以及获取其他常用时间戳

    php 计算当日凌晨时间戳 以及获取其他常用时间戳(持续补充中...) 获取当天凌晨时间戳: echo strtotime(date('Y-m-d')); 以下再列举一些获取其他常用时间戳的方法 获取 ...

  6. Pyhon从入门到致命

    第一章 基础 1.python2和python3的区别 2.数据类型 2.1 int 整型 2.2 str 字符串不可变类型 2.3 bool 布尔类型 2.4 list 列表 2.5 tuple 元 ...

  7. Stall Reservations POJ - 3190 (贪心+优先队列)

    Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11002   Accepted: 38 ...

  8. ghost模板总结

    ghost模板的二次开发相对容易,附文档: http://themes.ghost.org/v0.6.0/docs/meta_title 这里有各行变量的说明. {{#is "home&qu ...

  9. 用Python表达对Android的想法

    组员:喻航,张子东 视频:点我 #DISCARD ANDROID TODAY! import turtle import turtle as gui #setting turtle.screensiz ...

  10. POJ 1609 Tiling Up Blocks

    Tiling Up Blocks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4675   Accepted: 1824 ...