Poj 2165 Milking Grid(kmp)

Milking Grid
Time Limit: 3000MS Memory Limit: 65536K
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
USACO 2003 Fall

/*
kmp.
一开始传参数呵呵了.
忘了n和m相等的情况.
先把行看做一个整体做kmp.
然后把列看做一个整体做kmp.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 10001
#define MAXM 81
using namespace std;
int n,m,k,w,next[MAXN];
char g[MAXN][MAXM];
bool check(int x,int y,bool flag)
{
    if(flag)
    {
        for(int i=1;i<=m;i++) if(g[x][i]!=g[y][i]) return false;
        return true;
    }
    else
    {
        for(int i=1;i<=k;i++) if(g[i][x]!=g[i][y]) return false;
        return true;
    }
}
void kmp(int x,bool flag)
{
    int p=0;
    for(int i=2;i<=x;i++)
    {
        p=next[i-1];
        while(p&&!check(i,p+1,flag)) p=next[p];
        if(check(i,p+1,flag)) p++;
        next[i]=p;
    }
}
void slove()
{
    kmp(n,1);k=n-next[n];
    memset(next,0,sizeof next);
    kmp(m,0);w=m-next[m];
    return ;
}
int main()       
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
        cin>>g[i][j];       
    slove();
    printf("%d\n",k*w);
    return 0;
}

转载于:https://www.cnblogs.com/nancheng58/p/10068086.html

windchill安装搭建(保姆式) 保姆式搭建windchill 材料准备 Vmware工具,用来创建和打开虚拟机的工具 安装系统的镜像文件 数据库安装文件,这里是Oracle数据库 Windchill的安装包 Vmware工具,用来安装和打开虚拟机的软件 Windowsserver2008的镜像工具,用来安装虚拟机环境的系统,如果你有win2007或win2010的也可以,在做虚拟机时,需要先安装系统。 Oracle数据库安装包 Windchill11M030的安装包 (安装包如有需要可以私信邮箱发送) 虚拟机安装 安装虚拟机VMware 阅读详情

相关推荐

电力电子课设救星:用Simulink实现Buck变换器双闭环控制(PID调参技巧)

本文是电力电子课程设计的实用指南,详细讲解如何利用Simulink仿真平台实现Buck变换器的电压电流双闭环控制。文章核心聚焦于PID参数整定的实战技巧,提供了从手动调试口诀到MATLAB脚本自动优化的完整方案,旨在帮助学生高效完成课设,深入理解闭环控制原理并生成专业报告。

weixin_29179311的博客 298

poj 2165 Gunman

Gunman Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1351   Accepted: 492   Special Judge Description Consider a 3D scene with OXYZ coordinate system. Ax

长路漫漫 唯剑作伴 582

从开通VPS到搭建宝塔面板全教程

你在输入域名(此时我们可能没有类似aaa.com这样的域名,所以要输入VPS的IP地址)的时候,下面的根目录也会跟着变动,等输入完成后,你可以把根目录再改回成/www/wwwroot/dq。这时,在你的浏览器中,输入外网面板地址的URL,输入username和password,即可登陆宝塔面板。第一次登陆,需要绑定你的宝塔账号,你可以到宝塔的注册界面,用手机注册一个,然后绑定,首先看一下你的VPS操作系统是什么类型的(其实你在选择VPS的时候,就已经选定了,我选择的事Centos系统)。

kxltsuperr的专栏 3749

poj 2165 Gunman

//将三维坐标系转化为两个二维坐标系判断,分别x-z,z-y坐标系,相当于俯视图和左视图。//若直线与Window相交,则在左视图和俯视图上必相交。#include#include#includeusing namespace std;const double EP=1e-8;struct Point{double x, y, z;};struct Rect{Point lp, rp;}r

taozifish的专栏 812

转义序列字符(\0,\n,\r,\t,\v,\a,\f,\b,\\,\‘,\“,\?)详解,转义字符对应的全称,输出结果和对应的ASCII码值详解;

转义序列字符(\0,\n,\r,\t,\v,\a,\f,\b,\\,\',\",\?)详解,转义字符对应的全称,输出结果和对应的ASCII码值详解;

南城花开过的博客 3万+

电力-平衡式IEC 60870-5-101规约报文解析

本文详细介绍了电力自动化中平衡式IEC 60870-5-101规约的应用,包括链路建立与初始化、对时、遥控操作、数据上送和总召唤等关键步骤,通过实例解析了报文格式和交互过程,是理解配网自动化通信的重要参考资料。

让你爱上电路设计 5697

X - Milking Grid

Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description

mr_lee 902

IEC61850实战:从ICD文件解析到模型构建

本文深入解析IEC61850标准中的ICD文件结构,从Header、IED到DataTypeTemplates部分,详细介绍了如何构建电力自动化设备的数据模型。通过实战案例展示ICD文件的创建过程,并分享常见问题的调试技巧,帮助工程师快速掌握IEC61850建模方法,提升电力系统自动化项目的实施效率。

weixin_26841743的博客 499

POJ - 2185 Milking Grid

Milking Grid POJ - 2185  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, Farme

什么样的小孩 的博客 459

全国各省份影像下载地址(11级别)

cesium中使用urltemplate加载,leaflet中使用tile加载,具体加载有问题可以给我留言。

资深三维GIS开发 5178

【网络与爬虫 44】Canvas指纹伪造技术:突破浏览器图形渲染检测的终极指南

Canvas和WebGL指纹是现代反爬虫系统中最难绕过的检测技术之一,它们通过分析浏览器图形渲染的细微差异来识别用户设备。本文将深入解析Canvas和WebGL指纹的工作原理,探讨其在反爬虫检测中的应用,并提供多种有效的伪造和绕过策略,帮助开发者理解并应对这些高级检测技术。

熵数实验室 1213

POJ 2185(最大平铺矩阵)

Language: Default Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4346   Accepted: 1780 Description 给定R(1 *C (1 的矩阵,求它的最大平铺矩阵,不够的地方可部分平铺,但不可

nike0good |Oier&ACMer | 熟能生巧 1585

MIMO-OFDM通信系统性能仿真及MATLAB实现

将MIMO和OFDM技术结合起来,可以充分利用两者的优点,进一步提高无线通信系统的性能。在MIMO-OFDM系统中,多个天线同时发射多个子载波,称为多天线多载波(MIMO-OFDM)系统。随着无线通信技术的不断发展,MIMO-OFDM技术因其高效、可靠和适应性等优点已被广泛应用于新一代通信系统中。本篇文章旨在介绍MIMO-OFDM通信系统的基本原理及其性能评估方法,并结合MATLAB提供相关代码实现。本篇文章介绍了MIMO-OFDM通信系统的基本原理和性能评估方法,并结合MATLAB提供了相关的实现代码。

学习使你进步。 2220

POJ2185 Milking Grid

POJ2185 Milking Grid Time Limit:3000MS Memory Limit:65536K Total Submissions:3220 Accepted:1317 Description Every morning when they are milked, the Farmer John's co...

weixin_30826095的博客 190

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

usaco Milking Cows 报告

题意: 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶。第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒。第二个农民在700秒开始,在 1200秒结束。第三个农民在1500秒开始2100秒结束。期间最长的至少有一个农民在挤奶的连续时间为900秒(从300秒到1200秒),而最长的无人挤奶的连续时间(从挤奶开始一直到挤奶结束)为300秒(从1200秒到1500秒)。 ...

李世操的空间 205

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj 2185 Milking Grid KMP

Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5046   Accepted: 2113 Description Every morning when they are milked, the Farmer John's cows for

停不下的脚步 2065

USACO 1.2 Milking Cows (milk2)

/* ID: haolink1 PROG: milk2 LANG: C++ */ //#include #include #include #include using namespace std; typedef unsigned int u_int; class TimeInterval{ public: int begin_; int end_; TimeI

Hello World! 1473

POJ - 3044 D - City Skyline

The best part of the day for Farmer John's cows is when the sun sets. They can see the skyline of the distant city. Bessie wonders how many buildings the city has. Write a program that assists the cow

Marcus-Bao的个人主页 1202

kmp A B C 题解

A poj 1961 Period For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the l

qq_40924271的博客 334

Milking Grid@POJ 2185

Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 &lt;= R &lt;= 10,000) rows by C (1 &lt;= C &lt;= 75) columns. As we all know, Farmer John is quite the ...

李狗嗨acc 205

POJ 2185 (字符串最小覆盖)

Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3524   Accepted: 1446 Description Every morning when they are milked, the Farmer John's cows form

Canon of Code 1121

POJ 2185 Milking Grid(KMP)

个人博客→TanJX的自留地 Milking Grid Every morning when they are milked, the Farmer John’s cows form a rectangular grid that is R (1 &lt;= R &lt;= 10,000) rows by C (1 &lt;= C &lt;= 75) columns. As we all know...

Tan_JX 271

poj2185 Milking Grid(KMP运用)

poj2185 Milking Grid(KMP运用)

1754

poj 2185 (最小重复字符矩阵)

Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9923 Accepted: 4312 Description Every morning when they are milked, the Farmer John’s cows form a rectangular grid ...

越看越喜欢啊 565

【R - Milking Time】

思路: 不是普通01背包吗?有两个问题: 手推样例就可以发现,如果不对区间 sort,则裸的01背包无法得出正确结果。 即使根据右端点排序后进行01背包,可能是对的,但是会 TLE。 那么现在为了降低时间复杂度,将对每个点时间的 dp 变为对每个物品(区间)的 dp。 又出现一个问题:dp[i] 应该代表 “ 必须使用 i 区间 ”,还是 “ 前 i 个区间可以得到的最优解 ” ? 答案:...

Masker 273
上一篇: jQuery实现瀑布流布局详解(PC和移动端)
下一篇: 码云创建远程仓库总结
weixin_30881367
博客等级 码龄11年 119粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值