ural 1468
写了好久,不知道为什么不过,也不清楚到底卡在哪里。。。
只好看别人的代码,感觉除了HASH不一样外,倒没什么特别之处。同时参考那论文写的。。
http://blog.csdn.net/jyysc2010/article/details/9964513
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#define Min(a,b) (a<b?a:b)
struct node
{
int x,y;
} hash[],a1,a2;
int p=;
int n,m,f[][],ans,x1,x2,y1,y2,a[][],g[][],b[],next[],start[],tot;
long long s[]; void insert(int x,node t)//将HASH值x插入链表
{
hash[++tot]=t;
next[tot]=start[x];
start[x]=tot;
} bool cmp(int x,int l)//比较HASH值为X的相同矩阵是否出现过
{
int i,j;
for (int g=start[x]; g; g=next[g])
{
a2=hash[g];
j=l;
for (i=; i<l&&j>=l; i++)
if (f[a1.x][a1.y-i]!=f[a2.x][a2.y-i]) break;
if (i>=l)
{
if (l>ans) ans=l,x1=a1.x,y1=a1.y,x2=a2.x,y2=a2.y;
return true;
}
}
return false;
} int main()
{
int i,j,k,l,r;
char c;
scanf("%d%d%*c",&n,&m);
for (i=; i<=n; i++)
{
for (j=; j<=m; j++)
{
scanf("%c",&a[i][j]);
a[i][j]-=;
}
scanf("%*c");
}
s[]=;
for (i=; i<=n; i++) s[i]=(p*s[i-])&; r=Min(n,m);
l=;
while (l<=r)
{
k=l+r>>;
for (i=; i<=n; i++)
for (j=; j<=m; j++)
{
if (i<k) f[i][j]=f[i-][j]*p+a[i][j]&;
else f[i][j]=((f[i-][j]-a[i-k][j]*s[k-]&)+&)*p+a[i][j]&;//减去最高位,加上最低位 }//f[i][j]存下第j列第i行往上长度为k的串的HASH值
memset(start,,sizeof(start));
tot=;
for (j=; j<=m&&i>n; j++)
for (i=k; i<=n; i++)
{
if (j<k) g[i][j]=g[i][j-]*p+f[i][j]&;
else
{
g[i][j]=((g[i][j-]-f[i][j-k]*s[k-]&)+&)*p+f[i][j]&;
if (cmp(g[a1.x=i][a1.y=j],k)) break;
insert(g[i][j],a1);
}
}//g[i][j]存下右下角为第i行第j列长度为k的矩阵的HASH值
if (j<=m) l=k+;
else r=k-; }
if (ans) printf("%d\n%d %d\n%d %d\n",ans,x1-ans+,y1-ans+,x2-ans+,y2-ans+);
else printf("0\n");
return ;
}
ural 1468的更多相关文章
- BZOJ 1468: Tree
Description 真·树,问距离不大于 \(k\) 的点对个数. Sol 点分治. 同上. Code /********************************************* ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- Akka源码分析-ask模式
在我之前的博文中,已经介绍过要慎用Actor的ask.这里我们要分析一下ask的源码,看看它究竟是怎么实现的. 开发时,如果要使用ask方法,必须要引入akka.pattern._,这样才能使用ask ...
- $CF1141C Polycarp Restores Permutation$
\(problem\) 这题的大致意思就是已知数值差值 求1-n的排列 如果能构成排列 则输出这个排列.如果不能则输出-1 排列的值都是 大于1 而小于n的 而且没有相同的数字. 这题最关键的是 怎么 ...
- Leetcode0457--Circular Array Loop
[转载请注明]https://www.cnblogs.com/igoslly/p/9339478.html class Solution { public: bool circularArrayLoo ...
- 01--TCP状态转换
参考大牛文章: http://www.cnblogs.com/qlee/archive/2011/07/12/2104089.html
- Python语言之变量2(命名规则,类型转换)
1.命名规则 1.起始位为字母(大小写)或下划线('_') 2.其他部分为字母(大小写).下划线('_')或数字(0-9) 3.大小写敏感 2.先体验一把: #Ask the user their n ...
- Linux内存压力测试-memtester工具
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- hibernate+struts2
一.环境 添加struts2和hibernate的jar包.创建web.xml(配置struts的过滤器).struts2.xml和hibernate.cfg.xml(设置一些数据库参数). 二.创建 ...
- mysql_基础1
初学mysql,感觉挺有意思的. mysql指令的一些参数: promrt修改提示符: PROMPT \D mysql的语法规范: 一些函数: 创建数据库: SHOW CREATE DATABAS ...
- python tips:描述符descriptor
描述符(descriptor)是实现了__get__.__set__.__del__方法的类,进一步可以细分为两类: 数据描述符:实现了__get__和__set__ 非数据描述符:没有实现__set ...
- btrfs基础
btrfs文件系统简介 btrfs文件系统:技术预览版(Centos7) Btrfs(B-tree.Butter FS.Better FS),GPL授权,Orale2007提出是想用来取代Ext文 ...