POJ 2185 Milking Grid KMP(矩阵循环节)
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 7153 | Accepted: 3047 |
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
//作者:1085422276
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
//#include<bits/stdc++.h>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
const int inf = ;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
ll temp,p;
if(b==)
{
x=;
y=;
return a;
}
p=exgcd(b,a%b,x,y);
temp=x;
x=y;
y=temp-(a/b)*y;
return p;
}
//*******************************
char mp[][];
int n,m,p[];
int is_equal(int i,int j)
{
for(int k=;k<m;k++)
{
if(mp[i][k]!=mp[j][k])return ;
}
return ;
}
int is_equaf(int i,int j)
{
for(int k=;k<n;k++)
{
if(mp[k][i]!=mp[k][j])return ;
}
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(p,,sizeof(p));
for(int i=;i<n;i++)
{
scanf("%s",mp[i]);
}
// for(int i=1;i<=n;i++)cout<<mp[i]<<endl;
//return 0;
int j=;
for(int i=;i<m;i++)
{
while(j&&!is_equaf(i,j))j=p[j];
if(is_equaf(i,j))j++;
p[i+]=j;
}
int l;
l=m-(p[m]);
memset(p,,sizeof(p));
j=;
for(int i=;i<n;i++)
{
while(j&&!is_equal(i,j))j=p[j];
if(is_equal(i,j))j++;
p[i+]=j;
}
int r;
r=n-(p[n]);
cout<<l*r<<endl;
}
return ;
}
代码
POJ 2185 Milking Grid KMP(矩阵循环节)的更多相关文章
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- POJ 2185 Milking Grid [KMP]
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8226 Accepted: 3549 Desc ...
- [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最小循环节)
http://poj.org/problem?id=2185 题意: 给出一个r行c列的字符矩阵,求最小的覆盖矩阵可以将原矩阵覆盖,覆盖矩阵不必全用完. 思路: 我对于字符串的最小循环节是这么理解的: ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- POJ 2185 Milking Grid(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- Poj 2165 Milking Grid(kmp)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, ...
随机推荐
- Mongodb for C# 分组查询
#region 排序获取集合 static List<BsonDocument> GetPagerWithGroup(string connectionString, string dat ...
- CNN 美国有线电视新闻网 wapCNN WAP 指无线应用通讯协议 ---- 美国有线电视新闻网 的无线应用
wapCNN wap指无线应用通讯协议 CNN美国有线电视新闻网 固, wapCNN 美国有线电视新闻网的无线应用 -------------------------------------- ...
- motto6
当你发现自己不错的时候,要适当的给自己加点凉水,让自己知道自己离“不错”还很远.
- codeforces 258div2 A Game With Sticks(DP)
题目链接:http://codeforces.com/contest/451/problem/A 解题报告:有n跟红色的棍子横着放,m根蓝色的棍子竖着放,它们形成n*m个交点,两个人轮流在里面选择交点 ...
- sql大全
推荐一. 简单查询 简单的Transact-SQL查询只包括选择列表.FROM子句和Where子句.它们分别说明所查询列.查询的表或视图.以及搜索条件等. 例如,下面的语句查询testtable表 ...
- mac os 安装 pkg-config
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.tar.gz . env LDFLAGS="-framework ...
- error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不匹配值“2”
error: vtkCommon.lib(vtkSmartPointerBase.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不 ...
- facedetect
继续学习大神的博文http://www.cnblogs.com/tornadomeet/archive/2012/03/22/2411318.html
- 最近win7更新后出现第二次打开IDE(delphi2007)的时候提示无法打开"EditorLineEnds.ttr"这个文件
kb2982791 - 2014年8月12日更新 - http://support.microsoft.com/kb/2982791kb2970228 - 2014年8月12日更新 - http:// ...
- 使用nginx的proxy_cache做网站缓存
为什么要做web cache,我想大家最主要的是解决流量的压力.随着网站流量的提升,如果只是单台机器既处理静态文件,又处理动态脚本,显然效率很难上升,不能处理日益上涨的流量压力.与此同时某些网站的页面 ...