写了好久,不知道为什么不过,也不清楚到底卡在哪里。。。

只好看别人的代码,感觉除了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的更多相关文章

  1. BZOJ 1468: Tree

    Description 真·树,问距离不大于 \(k\) 的点对个数. Sol 点分治. 同上. Code /********************************************* ...

  2. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  3. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  4. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  5. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  6. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  7. 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 ...

  8. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  9. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

随机推荐

  1. 开启和安装Kubernetes 基于Docker For Windows

    0.最近发现,Docker For Windows Stable在Enable Kubernetes这个问题上是有Bug的,建议切换到Edge版本,并且采用下文AliyunContainerServi ...

  2. Akka源码分析-Remote-Creating Actors Remotely

    在akka官网中关于远程actor交互,介绍了两种方法,一种是通过actorSelection查询,另一种是通过actorOf在远程节点创建一个actor.actorSelection我们之前的博客中 ...

  3. ASP.NET MVC5 之数据迁移

    SQL 中新建数据库 DataSystem 1.web.config 数据库连接字符串: <add name="APPDataConnection" connectionSt ...

  4. hdu2027

    http://acm.hdu.edu.cn/showproblem.php?pid=2027 #include<iostream> #include<stdio.h> #inc ...

  5. ACM_巧克力

    Chocolate,Chocolate Time Limit: 2000/1000ms (Java/Others) Problem Description: 都说发神喜欢吃巧克力,有一次发神徒弟买了一 ...

  6. EF 新增数据时提示it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element

    it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionM ...

  7. 关于idea failed to start SceneBuilder 的解决方法

    问题描述: javaFx无法启动SceneBuilder. 问题原因: SceneBuilder不正当配置. 解决方法:1. 下载SceneBuilder   https://www.oracle.c ...

  8. python gdal 修改shp文件的属性值

    driver = ogr.GetDriverByName('ESRI Shapefile')datasource = driver.Open(shpFileName, 1)layer = dataso ...

  9. SQL基本操作——函数

    函数的类型:在 SQL 中,基本的函数类型和种类有若干种.函数的基本类型是:Aggregate 函数.Scalar 函数. Aggregate 函数:操作面向一系列的值,并返回一个单一的值,下面是SQ ...

  10. 控制台——屏蔽Ctrl+C快捷键对窗体的关闭功能

    导入SetCtrlHandlerHandler API //定义处理程序委托 public delegate bool ConsoleCtrlDelegate(int ctrlType); //导入S ...