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值,能达 ...
随机推荐
- hdu2081
#include <stdio.h> #include <malloc.h> int main(){ ]; char *p; int t; p=(); scanf(" ...
- 算法复习——树链剖分模板(bzoj1036)
题目: 题目背景 ZJOI2008 DAY1 T4 题目描述 一棵树上有 n 个节点,编号分别为 1 到 n ,每个节点都有一个权值 w .我们将以下面的形式来要求你对这棵树完成一些操作:I.CHAN ...
- mybatis学习(一)——mybatis简介
1.简介 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBati ...
- java面试题之stop()和suspend()方法为何不不推荐使⽤?
stop方法:他是不安全的,他会停止所有运行中的线程: suspend方法:容易发生死锁,虽然调用suspend方法目标线程会停下来,但是仍然持有之前的锁,其他线程都不能访问锁定的资源,就会造成死锁, ...
- Maven常用参数及其说明【转:http://blog.csdn.net/wangjunjun2008/article/details/18982089】
Maven常用参数及其说明 -h,--help Display help information-am,--also-make ...
- Bichrome Tree
Bichrome Tree 时间限制: 1 Sec 内存限制: 128 MB 题目描述 We have a tree with N vertices. Vertex 1 is the root of ...
- net3:Calendar控件的使用
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- Objective-C单例模式的常用实现
oc中单例模式可以使用以下方法来实现 + (YourClass *)sharedInstance { static dispatch_once_t once; static YourClass *sh ...
- Linux 下 GCC 编译共享库控制导出函数的方法
通过一些实际项目的开发,发现这样一个现象,在 Windows 下可以通过指定 __declspec(dllexport) 定义来控制 DLL(动态链接库)中哪些函数可以导出,暴露给其他程序链接使用,哪 ...
- T1046 旅行家的预算 codevs
http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D ...