嘟嘟嘟

当看到n <= 50 的时候就乐呵了,暴力就行了,不过最暴力的方法是O(n7)……然后加一个二分边长达到O(n6logn),然后我们接着优化,把暴力比对改成O(1)的比对hash值,能达到O(n5logn),到勉强能过……不过我们还可以在优化一下,把第一个矩阵中所有边长为 l 的子矩阵的hash值都存到一个数组中,然后sort一下,接着我们在枚举第二个矩阵的子矩阵,然后在数组中用lower_bound的查询就行。这样的话复杂度应该是O(n3log(n2) * logn)了。

~~求一个矩阵的哈希值就是每一行的哈希值之和~~

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int INF = 0x3f3f3f3f;
const int eps = 1e-;
const int maxn = ;
const ull base = ; //请无视
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, a[][maxn][maxn];
ull has[][maxn][maxn];
ull f[maxn], b[maxn * maxn];
int cnt = ; ull calc(int x, int y, int l, bool flag)
{
ull ret = ;
for(int i = x; i <= x + l - ; ++i) ret += has[flag][i][y + l - ] - has[flag][i][y - ] * f[l];
return ret;
}
bool judge(int x)
{
cnt = ;
for(int i = ; i <= n - x + ; ++i)
for(int j = ; j <= n - x + ; ++j)
b[++cnt] = calc(i, j, x, );
sort(b + , b + cnt + );
for(int i = ; i <= n - x + ; ++i)
for(int j = ; j <= n - x + ; ++j)
{
ull ha = calc(i, j, x, );
if(*lower_bound(b + , b +cnt + , ha) == ha) return ;
}
return ;
} int main()
{
n = read();
for(int k = ; k <= ; k++)
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) a[k][i][j] = read();
f[] = ;
for(int i = ; i <= n; ++i) f[i] = f[i - ] * base;
for(int k = ; k <= ; ++k)
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) has[k][i][j] = has[k][i][j - ] * base + a[k][i][j];
int L = , R = n;
while(L + < R)
{
int mid = (L + R) >> ;
if(judge(mid)) L = mid;
else R = mid - ;
}
write(judge(L + ) ? L + : L); enter;
return ;
}

[JSOI2008]Blue Mary的战役地图的更多相关文章

  1. bzoj1567: [JSOI2008]Blue Mary的战役地图

    将矩阵hash.s[0]忘了弄成0,输出中间过程发现了. hash.sort.判重.大概这样子的步骤吧. #include<cstdio> #include<cstring> ...

  2. BZOJ 1567: [JSOI2008]Blue Mary的战役地图( 二分答案 + hash )

    二分答案, 然后用哈希去判断... ------------------------------------------------------------------------- #include ...

  3. BZOJ 1567: [JSOI2008]Blue Mary的战役地图

    1567: [JSOI2008]Blue Mary的战役地图 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1011  Solved: 578[Sub ...

  4. BZOJ 1567: [JSOI2008]Blue Mary的战役地图 矩阵二维hash

    1567: [JSOI2008]Blue Mary的战役地图 Description Blue Mary最近迷上了玩Starcraft(星际争霸) 的RPG游戏.她正在设法寻找更多的战役地图以进一步提 ...

  5. [JSOI2008]Blue Mary的战役地图(二分+哈希)

    Blue Mary最近迷上了玩Starcraft(星际争霸) 的RPG游戏.她正在设法寻找更多的战役地图以进一步提高自己的水平. 由于Blue Mary的技术已经达到了一定的高度,因此,对于用同一种打 ...

  6. B1567 [JSOI2008]Blue Mary的战役地图 二分答案+hash

    一开始以为是dp,后来看了一下标签...二分答案?之前也想过,但是没往下想,然后之后的算法就顺理成章,先求出第一个地图的所有子矩阵的hash值,然后求第二个,在上一个地图例二分查找,然后就没了. 算法 ...

  7. BZOJ1567 [JSOI2008]Blue Mary的战役地图 二分答案 哈希

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1567 题意概括 给出两个n*n的数字矩阵,问最大公共正方形边长. 题解 先二分答案一个m,对于每一 ...

  8. [JSOI2008]Blue Mary的战役地图——全网唯一一篇dp题解

    全网唯一一篇dp题解 网上貌似全部都是哈希+二分(反正我是大概baidu了翻了翻)(还有人暴力AC了的..) 哈希还是相对于dp还是比较麻烦的. 而且正确性还有可能被卡(当然这个题不会) 而且还容易写 ...

  9. 【矩阵哈希】【二分答案】【哈希表】bzoj1567 [JSOI2008]Blue Mary的战役地图

    引用题解:http://hzwer.com/5153.html 当然,二分可以换成哈希表. #include<cstdio> #include<iostream> #inclu ...

随机推荐

  1. oracle 合并列的函数wm_concat

    oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_concat(column)函数实现字段合并,如果您对oracle wm_concat( ...

  2. PHP错误日志和内存查看

    1.通过命令查看服务器上一共开了多少的 php-cgi 进程: ps -fe |grep "php-fpm"|grep "pool"|wc -l 2.查看FPM ...

  3. 在IIS7中应用Application Request Routing配置反向代理

    配置反向代理软件.zip 开启Proxy项: 该设置表面只有HTTP_HOST为phpweb.leven.com.cn的URL才能通过该规则,如果您绑定了多个域名,可以根据多次增加或者通过正则表达式的 ...

  4. 移动端Web Meta标签

    原文  http://blog.segmentfault.com/jianjian_532633/1190000000654839 添加到推刊   在介绍移动端特有 meta 标签之前,先简单说一下 ...

  5. IOS微信后台运行时候倒计时暂停问题

    链接:https://pan.baidu.com/s/1i7cSkqL 密码:g80i 最近给央视做了个H5答题游戏,但在倒计时上遇到一个终端问题:手机端按Home键将微信收入后台之后,IOS11 会 ...

  6. 了解RabbitMQ

    消息队列可以实现流量削峰.降低系统耦合度.提高系统性能等. RabbitMQ是一个实现了AMQP协议(Advanced Message Queue Protocol)的消息队列. RabbitMQ中的 ...

  7. C# try catch嵌套

    try catch嵌套之后出现异常执行顺序: static void Main(string[] args) { try { Console.WriteLine("------------- ...

  8. PHP网站(Drupal7)响应过慢之“Wating(TTFB)时间过长”

    直接上图: 这是Chrome浏览器自带的工具分析的.整个url请求的时间为2.59秒,最大的耗时在Wating(TTFB, Time To First Byte),消耗了2.59秒(应该是其他时间太短 ...

  9. solidity 语法学习

    基于 cryptozombies.io ZombieFactory pragma solidity ^0.4.19; contract ZombieFactory { // 事件, web3.js 可 ...

  10. Android Studio 使用Intent实现页面的跳转(带参数)

    不管是在APP,还是在网站中,页面之间的跳转都是很常见的,本文主要讲一下在APP中,如何通过Intent实现页面的跳转. 不带参数: 写在MainActivity页面的代码: Intent inten ...