大概算是我学KMP简单题以来最废脑子的KMP题目了 , 当然细节并不是那么多 , 还是码起来很舒服的 , 题目中描写的平铺是那种瓷砖一样上下对齐的平铺 , 刚开始以为像地砖一样可以交错着铺 . . . 
需要两次kmp..我用的是题解的方法写第一次kmp...这样找起来似乎更清晰.
下面是代码
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const long long modn=;
char a[maxn][]={};
char s[]={};
int nex[maxn]={};
int f[]={};
int n,m;
int main(){
scanf("%d%d",&n,&m);
int x,y;
for(int i=;i<n;i++){
scanf("%s",&a[i]);
strcpy(s,a[i]);
for(int j=m-;j>;j--){
s[j]=;
for(x=,y=;a[i][y];x++,y++){//x for s,y for a if(s[x]==){
x=;
}
if(s[x]!=a[i][y]){
break;
}
}
if(!a[i][y]){
f[j]++;
}
}
}
int i,j;
for(i=;i<m;i++){
if(f[i]==n){
break;
}
}int cnt=i;
j=-,nex[]=-,i=;
while(i<n){
if(j==-||strcmp(a[i],a[j])==){
nex[++i]=++j;
}else{
j=nex[j];
}
}
printf("%d",(n-nex[n])*cnt);
return ;
}

POJ2185 Milking Grid KMP两次(二维KMP)较难的更多相关文章

  1. CSS Grid基于网格的二维布局系统(详细教程)

    .grid-wrap{ display: inline-flex; padding: 20px; background: #f4f4f4; word-break: initial; } .handle ...

  2. POJ_2185_二维KMP

    http://poj.org/problem?id=2185 求最小覆盖矩阵,把KMP扩展到二维,行一次,列一次,取最小覆盖线段相乘即可. #include<iostream> #incl ...

  3. Match:Milking Grid(二维KMP算法)(POJ 2185)

    奶牛矩阵 题目大意:给定一个矩阵,要你找到一个最小的矩阵,这个矩阵的无限扩充的矩阵包含着原来的矩阵 思路:乍一看这一题确实很那做,因为我们不知道最小矩阵的位置,但是仔细一想,如果我们能把矩阵都放在左上 ...

  4. 题解报告:poj 2185 Milking Grid(二维kmp)

    Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...

  5. POJ 2185 - Milking Grid (二维KMP)

    题意:给出一个字符矩形,问找到一个最小的字符矩形,令它无限复制之后包含原来的矩形. 此题用KMP+枚举来做. 一维的字符串匹配问题可以用KMP来解决.但是二维的就很难下手.我们可以将二维问题转化为一维 ...

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

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

  7. POJ2185 Milking Grid 【lcm】【KMP】

    Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...

  8. poj2185 Milking Grid【KMP】

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10084   Accepted: 4371 Des ...

  9. POJ2185 Milking Grid 题解 KMP算法

    题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next ...

随机推荐

  1. K. Random Numbers(Gym 101466K + 线段树 + dfs序 + 快速幂 + 唯一分解)

    题目链接:http://codeforces.com/gym/101466/problem/K 题目: 题意: 给你一棵有n个节点的树,根节点始终为0,有两种操作: 1.RAND:查询以u为根节点的子 ...

  2. Django初探(模板渲染、模板语音、simple_tag、母版子版、静态配置文件)

    一.首先我们用PyCharm来创建一个Django项目 终端命令:django-admin startproject sitename 图形创建:   这样一个Django项目就创建完成了,上面可以看 ...

  3. ldconfig是一个动态链接库管理命令

    ldconfig是一个动态链接库管理命令 为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfig ldconfig  命令的用途,主要是在默认搜寻目录(/lib和/usr/li ...

  4. MySQL创建相同表和数据命令

    创建和表departments结构和数据一样的表departments_t mysql> create table departments_t like departments; Query O ...

  5. ansible 下lineinfile详细使用 【转】

    转自 ansible 下lineinfile详细使用 - 散人 - 51CTO技术博客http://zouqingyun.blog.51cto.com/782246/1882367 一.简述 这几天在 ...

  6. Python设计模式中单例模式的实现及在Tornado中的应用

    单例模式的实现方式 将类实例绑定到类变量上 class Singleton(object): _instance = None def new(cls, *args): if not isinstan ...

  7. 137.Single Number II---位运算---《剑指offer》40

    题目链接:https://leetcode.com/problems/single-number-ii/description/ 题目大意:给出一串数,每个数都出现三次,只有一个数只出现一次,把这个出 ...

  8. 关于JavaScript中实现继承,及prototype属性

    感谢Mozilla 让我弄懂继承. JavaScript有八种基本类型,函数属于object.所以所有函数都继承自object.//扩展:对象,基本上 JavaScript 里的任何东西都是对象,而且 ...

  9. LeetCode解题报告—— Best Time to Buy and Sell Stock

    Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a gi ...

  10. poj 1041(字典序输出欧拉回路)

    John's trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8641   Accepted: 2893   Spe ...