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值,能达 ...
随机推荐
- TOJ 2596: Music Notes
2596: Music Notes Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Submit: 3 ...
- 【UML】关联、依赖、泛化、实现等关系说明
导读:再上一篇博客中,介绍了UML的9种图,现在,将对UML中的关系进行总结.图很重要,但图形中的各种关系也很重要,这扯关系的事儿,从来都是大事儿. 一.基本定义 1.1 总体说明 1.2 具体定义 ...
- 微软.net一些类的源码
地址:http://referencesource.microsoft.com/#mscorlib/system/collections/generic/dictionary.cs 关键字:refer ...
- 九度oj 题目1135:字符串排序
题目描述: 先输入你要输入的字符串的个数.然后换行输入该组字符串.每个字符串以回车结束,每个字符串少于一百个字符. 如果在输入过程中输入的一个字符串为“stop”,也结束输入. 然后将这输入的该组字符 ...
- post 发送ajax请求
1.ajax五步曲 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- poj1930 数论
Dead Fraction Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1258 Accepted: 379 Desc ...
- MySQL 游戏排行榜
今天在坛子上看到了,顺便写下来. 有两种方法: 1.效率不高,因为有子查询.但是简洁.而且我对SOCRES表做了INDEX.所以性能上也差不了多少. mysql> show create tab ...
- ubuntu下用webbench做网站压力测试
安装依赖 exuberant-ctags sudo apt-get install exuberant-ctags 下载源码并安装 wget http://blog.s135.com/soft/lin ...
- Volley 源码解析 StringRequest解析
Android Vollety是一个很有用的框架,所以想借鉴前人思想,分析这个源代码. 参考: http://blog.csdn.net/crazy__chen/article/details/464 ...
- [Bzoj3205][Apio2013]机器人(斯坦纳树)(bfs)
3205: [Apio2013]机器人 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 977 Solved: 230[Submit][Status] ...