思路来自题解和一些博客

最麻烦的是样例没啥用- -

  1. /*
  2. HDU 6046 - hash [ hash,鸽巢 ] | 2017 Multi-University Training Contest 2
  3. 题意:
  4. 给出一个1e3*1e3的矩阵以及 一个 生成1e6*1e6的矩阵的随机函数
  5. 在1e6*1e6的矩阵中找到1e3*1e3的矩阵的位置
  6. 分析:
  7. 将1e3*1e3的矩阵每一个位置压入哈希表中,哈希值为其与之后63位所组成64位的值(不满64位就不压入)
  8. 由于 2^64 远大于 1e12 故可认为哈希值相同的是同一个位置
  9. 枚举大矩阵中的位置,若能在哈希表中找到这个位置的哈希值,则小矩阵头部的相对位置可以确定
  10. 但不需要枚举大矩阵中的每个位置,可以每隔1000行,隔900列枚举一个位置
  11. 这样根据鸽巢原理,枚举的这些位置至少有一个被小矩阵覆盖
  12.  
  13. 选隔900列而不是1000列的原因是 小矩阵每行最右端63个点没被压入哈希表,所以哈希表中的矩阵是 1000 * (1000-63)的
  14. */
  15. #include <bits/stdc++.h>
  16. using namespace std;
  17. #define LL unsigned long long
  18. const int N = 1e3+5;
  19. const int L = 1000;
  20. const int ZIP = 64;
  21. inline unsigned sfr(unsigned h, unsigned x) {
  22. return h >> x;
  23. }
  24. int f(LL i, LL j) {
  25. LL w = i * 1000000ll + j;
  26. int h = 0;
  27. for (int k = 0; k < 5; ++k) {
  28. h += (int) ((w >> (8 * k)) & 255);
  29. h += (h << 10);
  30. h ^= sfr(h, 6);
  31. }
  32. h += h << 3;
  33. h ^= sfr(h, 11);
  34. h += h << 15;
  35. return sfr(h, 27) & 1;
  36. }
  37. namespace HashMap{
  38. const int MOD = 1313131;
  39. struct Node {
  40. LL pos, val;
  41. int nxt;
  42. }node[N*N];
  43. int head[MOD], tot;
  44. void init() {
  45. memset(head, 0, sizeof(head));
  46. tot = 0;
  47. }
  48. void insert(LL v, LL p) {
  49. int t = v % MOD; tot++;
  50. node[tot].pos = p;
  51. node[tot].val = v;
  52. node[tot].nxt = head[t];
  53. head[t] = tot;
  54. }
  55. LL find(LL v) {
  56. for (int i = head[v%MOD]; i; i = node[i].nxt)
  57. if (node[i].val == v) return node[i].pos;
  58. return 0;
  59. }
  60. }
  61. char s[N];
  62. LL hs[N];
  63. int main()
  64. {
  65. int t; scanf("%d", &t);
  66. for (int tt = 1; tt <= t; tt++)
  67. {
  68. HashMap::init();
  69. for (int i = 1; i <= L; i++)
  70. {
  71. scanf("%s", s+1);
  72. hs[L+1] = 0;
  73. for (int j = L; j >= 1; j--)
  74. hs[j] = hs[j+1]<<1|(s[j]-'0');
  75. for (int j = 1; j <= L-ZIP+1; j++)
  76. HashMap::insert(hs[j], i*1024+j);
  77. }
  78. LL ans = 0; int x, y;
  79. for (int i = 1; i <= 1e6 && (!ans); i += 1000)
  80. for (int j = 1; j <= 1e6 && (!ans); j += 900)
  81. {
  82. if (j+ZIP-1 > 1e6) continue;
  83. LL val = 0;
  84. for (int k = ZIP-1; k >= 0; k--)
  85. val = val<<1|(f(i,j+k));
  86. ans = HashMap::find(val);
  87. if (ans != 0) x = i, y = j;
  88. }
  89. int px = x - ans / 1024 + 1, py = y - ans % 1024 + 1;
  90. printf("Case #%d :%d %d\n", tt, px, py);
  91. }
  92. }

  

HDU 6046 - hash | 2017 Multi-University Training Contest 2的更多相关文章

  1. hdu 6046 hash

    题: OwO http://acm.hdu.edu.cn/showproblem.php?pid=6046 (2017 Multi-University Training Contest - Team ...

  2. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  3. HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9

    /* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...

  4. HDU 5726 GCD (2016 Multi-University Training Contest 1)

      Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Give y ...

  5. HDU 5360 Hiking(优先队列)2015 Multi-University Training Contest 6

    Hiking Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  6. HDU OJ 4334 Trouble 2012 Multi-University Training Contest 4

    题目:click here 题意: 给定5组数据,每组数据选择一个数,看是否能找到5个数的和为零. 分析: 千万不要~~T~~ 普通线性查找: #include <iostream> #i ...

  7. hdu 6394 Tree (2018 Multi-University Training Contest 7 1009) (树分块+倍增)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=6394 思路:用dfs序处理下树,在用分块,我们只需要维护当前这个点要跳出这个块需要的步数和他跳出这个块去 ...

  8. HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)

    思路   如果进制为p    那么当x<p时 (p-1)*(p-x)=(p-(x+1))  *p +x     因为x<p  所以没有进位  所以高位上的数字为    p-(x+1). 根 ...

  9. HDU 4938 Seeing People(2014 Multi-University Training Contest 7)

    思路:根据出发时间把点往速度反方向移动 t*v的 的距离这样就可以当成 全部点一起出发,再把y轴上的点固定不动相当于x轴的点向(-v2,v1)方向移动 .可以把所有点映射到x轴上进行统计即可(要记住同 ...

随机推荐

  1. libtool

    [从网上摘录的,忘了从哪摘的了]   libtool常见于autoconf/automake,单独用的例子很少,所以我想仔细研究一下,为将来兄弟们看起来方便. 一.libtool的作用offer a ...

  2. 【转帖】Linux 桌面进化史

    Linux 桌面进化史 https://www.oschina.net/news/109440/how-linux-desktop-grown 与之前认识到的一样 桌面最开始 是 施乐公司研发的. 后 ...

  3. [转帖]Vim全键盘操作

    https://www.cnblogs.com/pzqu/p/11416436.html Vim脱离鼠标第一步 平时不可缺少的会用到vim,但是避免不了鼠标,事实上,省略鼠标是完全可以的,没有想像中那 ...

  4. Photon Server初识(六) --- 客户端与服务端消息传递

    前一章客户端与服务端连接成功,现在需要前后端进行数据传递. 一.前端发送消息.在项目Scripts目录中新建脚本 TestSer.cs.并挂载到相机上 二.客户端发送数据给服务端.编辑客户端代码 Te ...

  5. jsp页面报错,各种错误码意思

    基本原则: 2xx = Success(成功) 3xx = Redirect(重定向) 4xx = User error(客户端错误) 5xx = Server error(服务器端错误) 状态码 ( ...

  6. 【KMP】OKR-Periods of Words

    [KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...

  7. rabbitmq消息队列,消息发送失败,消息持久化,消费者处理失败相关

    转:https://blog.csdn.net/u014373554/article/details/92686063 项目是使用springboot项目开发的,前是代码实现,后面有分析发送消息失败. ...

  8. 利用ant-design封装react的地址输入组件

    在上一节利用element-ui封装地址输入的组件留下了个尾巴,说react搭配ant-design封装一下地址输入的组件的.本来应该早早就完成的,但是由于这中间发生了一些事情,导致了突发性的换了工作 ...

  9. VS显示方法引用

    菜单栏 工具->选项->文本编辑器->所有语言->CodeLens 勾上即可

  10. 验证组件FluentValidation的使用示例

    官方文档:https://fluentvalidation.net/start#complex-properties 示例Demo:https://github.com/DavideYang125/F ...