嘟嘟嘟

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

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

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<cstdlib>
  7. #include<cctype>
  8. #include<vector>
  9. #include<stack>
  10. #include<queue>
  11. using namespace std;
  12. #define enter puts("")
  13. #define space putchar(' ')
  14. #define Mem(a) memset(a, 0, sizeof(a))
  15. typedef long long ll;
  16. typedef unsigned long long ull;
  17. typedef double db;
  18. const int INF = 0x3f3f3f3f;
  19. const int eps = 1e-;
  20. const int maxn = ;
  21. const ull base = ; //请无视
  22. inline ll read()
  23. {
  24. ll ans = ;
  25. char ch = getchar(), last = ' ';
  26. while(!isdigit(ch)) {last = ch; ch = getchar();}
  27. while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
  28. if(last == '-') ans = -ans;
  29. return ans;
  30. }
  31. inline void write(ll x)
  32. {
  33. if(x < ) x = -x, putchar('-');
  34. if(x >= ) write(x / );
  35. putchar(x % + '');
  36. }
  37.  
  38. int n, a[][maxn][maxn];
  39. ull has[][maxn][maxn];
  40. ull f[maxn], b[maxn * maxn];
  41. int cnt = ;
  42.  
  43. ull calc(int x, int y, int l, bool flag)
  44. {
  45. ull ret = ;
  46. for(int i = x; i <= x + l - ; ++i) ret += has[flag][i][y + l - ] - has[flag][i][y - ] * f[l];
  47. return ret;
  48. }
  49. bool judge(int x)
  50. {
  51. cnt = ;
  52. for(int i = ; i <= n - x + ; ++i)
  53. for(int j = ; j <= n - x + ; ++j)
  54. b[++cnt] = calc(i, j, x, );
  55. sort(b + , b + cnt + );
  56. for(int i = ; i <= n - x + ; ++i)
  57. for(int j = ; j <= n - x + ; ++j)
  58. {
  59. ull ha = calc(i, j, x, );
  60. if(*lower_bound(b + , b +cnt + , ha) == ha) return ;
  61. }
  62. return ;
  63. }
  64.  
  65. int main()
  66. {
  67. n = read();
  68. for(int k = ; k <= ; k++)
  69. for(int i = ; i <= n; ++i)
  70. for(int j = ; j <= n; ++j) a[k][i][j] = read();
  71. f[] = ;
  72. for(int i = ; i <= n; ++i) f[i] = f[i - ] * base;
  73. for(int k = ; k <= ; ++k)
  74. for(int i = ; i <= n; ++i)
  75. for(int j = ; j <= n; ++j) has[k][i][j] = has[k][i][j - ] * base + a[k][i][j];
  76. int L = , R = n;
  77. while(L + < R)
  78. {
  79. int mid = (L + R) >> ;
  80. if(judge(mid)) L = mid;
  81. else R = mid - ;
  82. }
  83. write(judge(L + ) ? L + : L); enter;
  84. return ;
  85. }

[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. Java虚拟机_运行时数据区

    Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域. 这些区域都有各自的用途.各自的创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,有些区域则是依赖用户线程启动 ...

  2. Netty面试

    声明:此文章非本人所 原创,是别人分享所得,如有知道原作者是谁可以联系本人,如有转载请加上此段话  1.BIO.NIO 和 AIO 的区别? BIO:一个连接一个线程,客户端有连接请求时服务器端就需要 ...

  3. 插入sql返回主键id

    <insert id="insertSelective" parameterType="com.xxx.model.XDetail" useGenerat ...

  4. TortoiseGit用户手册

    3 配置TortoiseGit 3.1 生成公钥 生成SSH安全密钥,提供给GIT版本库管理员以访问Git 版本库,点击桌面上生成的图标 然后执行执行“ssh-keygen”生成自己的公钥: 一路回车 ...

  5. PECL: configuration option "php_ini" is not set to php.ini location

    message similar to: configuration option "php_ini" is not set to php.ini locationYou shoul ...

  6. IDEA下的第一个springBoot

    1.第一步打开File->New->Project,SDK根据自己的需要选择,我这边选的是java7 2.Next之后 设置group 和artifact,根据自己的需要进行修改. 3.导 ...

  7. 推荐 VSCode 上特别好用的 Vue 插件 - vetur

    作者 @octref 此前 V2EX 发过帖子,最近新增代码补全功能,综合比较应该是目前 VSCode 上面最好用的 Vue 插件. 能够实现在 .vue 文件中: 语法错误检查,包括 CSS/SCS ...

  8. Hive Metastore 连接报错

    背景 项目中需要通过一些自定义的组件来操控hive的元数据,于是使用了remote方式来存储hive元数据,使用一个服务后台作为gateway,由它来控制hive元数据. 现象 在windows上连接 ...

  9. 自动补全Typeahead

    采用 Typeahead (Bootstrap-3-Typeahead-master) <script type="text/javascript" src="/j ...

  10. opencv图像处理基础 (《OpenCV编程入门--毛星云》学习笔记一---五章)

    #include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgu ...