BZOJ1170 : [Balkan2007]Cipher
首先对于每个位置,求出它开始长度为y的横行的hash值,然后对于hash值再求一次竖列的hash值,排序后求出众数即可。
时间复杂度$O(n^2\log n)$。
#include<cstdio>
#include<algorithm>
#define N 1010
typedef unsigned long long ll;
const ll D1=197,D2=131;
int n,m,x,y,i,j,ans,t,cnt;char a[N][N];ll pow1[N],pow2[N],h[N][N],tmp;
struct P{int x,y;ll z;P(){}P(int _x,int _y,ll _z){x=_x,y=_y,z=_z;}}q[N*N],fin[N];
inline bool cmp(const P&a,const P&b){return a.z<b.z;}
inline bool cmp2(const P&a,const P&b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int main(){
scanf("%d%d",&n,&m);gets(a[0]);
for(i=1;i<=n;i++)gets(a[i]+1);
scanf("%d%d",&x,&y);
for(pow1[0]=pow2[0]=i=1;i<=n||i<=m;i++)pow1[i]=pow1[i-1]*D1,pow2[i]=pow2[i-1]*D2;
for(i=1;i<=n;i++){
for(tmp=0,j=1;j<y;j++)tmp=tmp*D1+a[i][j],h[i][j]=0;
for(j=y;j<=m;j++)h[i][j]=tmp=tmp*D1-pow1[y]*a[i][j-y]+a[i][j];
}
for(t=0,i=y;i<=m;i++){
for(tmp=0,j=1;j<x;j++)tmp=tmp*D2+h[j][i];
for(j=x;j<=n;j++)q[++t]=P(j-x+1,i-y+1,tmp=tmp*D2-pow2[x]*h[j-x][i]+h[j][i]);
}
for(std::sort(q+1,q+t+1,cmp),j=1,i=2;i<=t;i++)if(q[i-1].z!=q[i].z){
if(i-j>ans)ans=i-j,tmp=q[j].z;
j=i;
}
if(t-j+1>ans)ans=t-j+1,tmp=q[t].z;
printf("%d %d\n",x,y);
for(i=1;i<=t;i++)if(q[i].z==tmp)fin[++cnt]=P(q[i].x,q[i].y,0);
std::sort(fin+1,fin+cnt+1,cmp2);
for(i=0;i<x;puts(""),i++)for(j=0;j<y;j++)putchar(a[fin[1].x+i][fin[1].y+j]);
for(printf("%d\n",cnt),i=1;i<=cnt;i++)printf("%d %d\n",fin[i].x,fin[i].y);
return 0;
}
BZOJ1170 : [Balkan2007]Cipher的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 2012 Solved: 896[Submit][St ...
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6014 Solved: 2503[Submit ...
- freeCodeCamp:Caesars Cipher
让上帝的归上帝,凯撒的归凯撒. 下面我们来介绍风靡全球的凯撒密码Caesar cipher,又叫移位密码. 移位密码也就是密码中的字母会按照指定的数量来做移位. 一个常见的案例就是ROT13密码,字母 ...
- ural Cipher Message
Cipher Message Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- 紫书例题-Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret ser ...
- 【BZOJ-1031】字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5504 Solved: 2277[Submit ...
随机推荐
- Linux 基础知识(一) shell的&&和|| 简单使用
shell 在执行某个命令的时候,会返回一个返回值,该返回值保存在 shell 变量 $? 中.当 $? == 0 时,表示执行成功:当 $? == 1 时,表示执行失败. 有时候,下一条命令依赖前 ...
- IntelliJ IDEA 破解 - pycharm
MAC激活方法 下载破解文件 下载地址: https://files.cnblogs.com/files/resn/JetbrainsCrack-2.7-release-str.jar.zip 或者去 ...
- [整理]CSS3 滤镜
1.灰度 兼容 http://www.526net.com/blog/qianduan/226.html http://james.padolsey.com/demos/grayscale/grays ...
- 滚动视差插件skrollr.js
东西虽好,但也不能懒到自己一点都不去做总结,那么下方将会写出从网上找到,比较好的网址(应该是根据官网翻译的). 自己先做一个总结:这个插件兼容上做到了降级处理,虽然低端浏览器没有那么顺畅的效果,但是勉 ...
- 第9月第6天 push pop动画 生成器模式(BUILDER)
1. https://github.com/MichaelHuyp/QQNews 2.生成器模式(BUILDER) class MazeBuilder { public: virtual void B ...
- linux网络配置原理
一.网络连接的基本原理 http://www.cnblogs.com/dyllove98/archive/2013/08/06/3241294.html
- Expression Tree Build
The structure of Expression Tree is a binary tree to evaluate certain expressions.All leaves of the ...
- BAT修改文本内容
@echo off (for /f "delims=" %%a in (文件名) do ( set "str=%%a" setlocal enabledelay ...
- (转载)mysql:设置mysql的远程访问
1.登陆Mysqlmysql -u root -p2.允许任何IP访问,其中密码为admingrant all privileges on *.* to root@"%" iden ...
- 【转】java comparator 升序、降序、倒序从源码角度理解
原文链接:https://blog.csdn.net/u013066244/article/details/78997869 环境jdk:1.7+ 前言之前我写过关于comparator的理解,但是都 ...