BZOJ 1567: [JSOI2008]Blue Mary的战役地图 矩阵二维hash
1567: [JSOI2008]Blue Mary的战役地图
Description
Input
Output
Sample Input
1 2 3
4 5 6
7 8 9
5 6 7
8 9 1
2 3 4
Sample Output
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 2e5+, M = 1e3+,inf = 2e9; /*inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}*/
const ULL mod1 = 133700613937LL, mod2 = 10031LL;
ULL sqr1[],sqr2[],ahas[][],bhas[][]; LL a[][],b[][];
int n;
map<ULL, int > mp;
int ok(int w) {
mp.clear();
for(int i = w; i <= n; ++i) {
for(int j = w; j <= n; ++j)
{
mp[sqr1[n - i + ] * sqr2[n - j + ] * (ahas[i][j] + ahas[i-w][j-w] - ahas[i-w][j] - ahas[i][j-w])] = ;
}
}
for(int i = w; i <= n; ++i) {
for(int j = w; j <= n; ++j)
{
if(mp[sqr1[n - i + ] * sqr2[n - j + ] * (bhas[i][j] + bhas[i-w][j-w] - bhas[i-w][j] - bhas[i][j-w])])
return ;
}
}
return ;
}
int main() {
sqr1[] = 1LL;sqr2[] = 1LL;
for(int i = ; i <= ; ++i)
sqr1[i] = sqr1[i-] * mod1,
sqr2[i] = sqr2[i-] * mod2;
scanf("%d",&n);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
scanf("%lld",&a[i][j]),
ahas[i][j] = sqr1[i] * sqr2[j] * a[i][j],
ahas[i][j] += ahas[i][j-] + ahas[i-][j] - ahas[i-][j-];
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
scanf("%lld",&b[i][j]),
bhas[i][j] = sqr1[i] * sqr2[j] * b[i][j],
bhas[i][j] += bhas[i][j-] + bhas[i-][j] - bhas[i-][j-];
int ans = ;
for(int w = n; w >= ; w--) {
if(ok(w)) {
printf("%d\n",w);
return ;
}
}
printf("0\n");
return ;
}
BZOJ 1567: [JSOI2008]Blue Mary的战役地图 矩阵二维hash的更多相关文章
- BZOJ 1567: [JSOI2008]Blue Mary的战役地图( 二分答案 + hash )
二分答案, 然后用哈希去判断... ------------------------------------------------------------------------- #include ...
- BZOJ 1567: [JSOI2008]Blue Mary的战役地图
1567: [JSOI2008]Blue Mary的战役地图 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1011 Solved: 578[Sub ...
- bzoj 1567: [JSOI2008]Blue Mary的战役地图【二分+hash】
二维哈希+二分 说是二维,其实就是先把列hash了,然后再用列的hash值hash行,这样可以O(n)的计算一个正方形的hash值,然后二分边长,枚举左上角点的坐标然后hash判断即可 只要base选 ...
- Luogu P4398 [JSOI2008]Blue Mary的战役地图 矩阵哈希
其实可以二分矩阵边长但是我太懒了$qwq$. 把每个子矩阵扔到$map$里,然后就没了 #include<cstdio> #include<map> #include<i ...
- bzoj1567: [JSOI2008]Blue Mary的战役地图
将矩阵hash.s[0]忘了弄成0,输出中间过程发现了. hash.sort.判重.大概这样子的步骤吧. #include<cstdio> #include<cstring> ...
- [JSOI2008]Blue Mary的战役地图(二分+哈希)
Blue Mary最近迷上了玩Starcraft(星际争霸) 的RPG游戏.她正在设法寻找更多的战役地图以进一步提高自己的水平. 由于Blue Mary的技术已经达到了一定的高度,因此,对于用同一种打 ...
- B1567 [JSOI2008]Blue Mary的战役地图 二分答案+hash
一开始以为是dp,后来看了一下标签...二分答案?之前也想过,但是没往下想,然后之后的算法就顺理成章,先求出第一个地图的所有子矩阵的hash值,然后求第二个,在上一个地图例二分查找,然后就没了. 算法 ...
- BZOJ1567 [JSOI2008]Blue Mary的战役地图 二分答案 哈希
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1567 题意概括 给出两个n*n的数字矩阵,问最大公共正方形边长. 题解 先二分答案一个m,对于每一 ...
- [JSOI2008]Blue Mary的战役地图
嘟嘟嘟 当看到n <= 50 的时候就乐呵了,暴力就行了,不过最暴力的方法是O(n7)……然后加一个二分边长达到O(n6logn),然后我们接着优化,把暴力比对改成O(1)的比对hash值,能达 ...
随机推荐
- [adb 连接不上的原因] 汇总
http://www.cnblogs.com/dazhao/p/6534128.html 查看android studio 的sdk路径( 点击工具栏 ?号旁边的类似下载按钮) SDK_Manager ...
- python ConfigParser 学习
[安装] ConfigParser 是解析配置文件的第三方库,需要安装 pip install ConfigParser [介绍] ConfigParser 是用来读取配置文件(可以是.conf, ...
- iOS学习小结(一)
1.给类目添加属性需要使用runtime关联 #import <Foundation/Foundation.h> @interface NSURLRequest (AIFNetworkin ...
- 【Luogu】P2831愤怒的小鸟(手算抛物线+状压DP)
题目链接 设f[s]表示二进制集合表示下的s集合都打掉用了多少小鸟. 预处理出lne[i][j]表示i.j确定的抛物线能打掉的小鸟集合. 于是就有f[s|lne[i][j]]=min(f[s|lne[ ...
- CentOS7下安装Docker-Compose No module named 'requests.packages.urllib3'
在使用Docker的时候,有一个工具叫做 docker-compose,安装它的前提是要安装pip工具. 1.首先检查Linux有没有安装Python-pip包,直接执行 yum install p ...
- bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案
[Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 407 Solved: 325[S ...
- pageContext,request,session,application生命周期
equest是封装client端(也就是用户通过browser)提交的请求数据和属性的对象. response是封装web server端响应数据和属性的对象. 我们经常会将pageContext.r ...
- kail Linux 安装Parallels Tools
网上好多都是Parallels8的 针对Parallels 9 的还真不好找..... 自己捣鼓了一阵 终于可以安装了,但还是有错误,因为公司网络太不给力....回家再测试吧 1.在桌面新建一个文件夹 ...
- android图片上传
package com.example.center; import java.io.ByteArrayOutputStream;import java.io.InputStream; import ...
- raspi串口、python串口模块pyserial
一.安装 1.下载软件包pyserial-2.7.tar.gz 网址:https://pypi.python.org/pypi/pyserial 2.8uftp上传至/usr/local/src/ ...