HDU 6046 - hash | 2017 Multi-University Training Contest 2
思路来自题解和一些博客
最麻烦的是样例没啥用- -
- /*
- HDU 6046 - hash [ hash,鸽巢 ] | 2017 Multi-University Training Contest 2
- 题意:
- 给出一个1e3*1e3的矩阵以及 一个 生成1e6*1e6的矩阵的随机函数
- 在1e6*1e6的矩阵中找到1e3*1e3的矩阵的位置
- 分析:
- 将1e3*1e3的矩阵每一个位置压入哈希表中,哈希值为其与之后63位所组成64位的值(不满64位就不压入)
- 由于 2^64 远大于 1e12 故可认为哈希值相同的是同一个位置
- 枚举大矩阵中的位置,若能在哈希表中找到这个位置的哈希值,则小矩阵头部的相对位置可以确定
- 但不需要枚举大矩阵中的每个位置,可以每隔1000行,隔900列枚举一个位置
- 这样根据鸽巢原理,枚举的这些位置至少有一个被小矩阵覆盖
- 选隔900列而不是1000列的原因是 小矩阵每行最右端63个点没被压入哈希表,所以哈希表中的矩阵是 1000 * (1000-63)的
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define LL unsigned long long
- const int N = 1e3+5;
- const int L = 1000;
- const int ZIP = 64;
- inline unsigned sfr(unsigned h, unsigned x) {
- return h >> x;
- }
- int f(LL i, LL j) {
- LL w = i * 1000000ll + j;
- int h = 0;
- for (int k = 0; k < 5; ++k) {
- h += (int) ((w >> (8 * k)) & 255);
- h += (h << 10);
- h ^= sfr(h, 6);
- }
- h += h << 3;
- h ^= sfr(h, 11);
- h += h << 15;
- return sfr(h, 27) & 1;
- }
- namespace HashMap{
- const int MOD = 1313131;
- struct Node {
- LL pos, val;
- int nxt;
- }node[N*N];
- int head[MOD], tot;
- void init() {
- memset(head, 0, sizeof(head));
- tot = 0;
- }
- void insert(LL v, LL p) {
- int t = v % MOD; tot++;
- node[tot].pos = p;
- node[tot].val = v;
- node[tot].nxt = head[t];
- head[t] = tot;
- }
- LL find(LL v) {
- for (int i = head[v%MOD]; i; i = node[i].nxt)
- if (node[i].val == v) return node[i].pos;
- return 0;
- }
- }
- char s[N];
- LL hs[N];
- int main()
- {
- int t; scanf("%d", &t);
- for (int tt = 1; tt <= t; tt++)
- {
- HashMap::init();
- for (int i = 1; i <= L; i++)
- {
- scanf("%s", s+1);
- hs[L+1] = 0;
- for (int j = L; j >= 1; j--)
- hs[j] = hs[j+1]<<1|(s[j]-'0');
- for (int j = 1; j <= L-ZIP+1; j++)
- HashMap::insert(hs[j], i*1024+j);
- }
- LL ans = 0; int x, y;
- for (int i = 1; i <= 1e6 && (!ans); i += 1000)
- for (int j = 1; j <= 1e6 && (!ans); j += 900)
- {
- if (j+ZIP-1 > 1e6) continue;
- LL val = 0;
- for (int k = ZIP-1; k >= 0; k--)
- val = val<<1|(f(i,j+k));
- ans = HashMap::find(val);
- if (ans != 0) x = i, y = j;
- }
- int px = x - ans / 1024 + 1, py = y - ans % 1024 + 1;
- printf("Case #%d :%d %d\n", tt, px, py);
- }
- }
HDU 6046 - hash | 2017 Multi-University Training Contest 2的更多相关文章
- hdu 6046 hash
题: OwO http://acm.hdu.edu.cn/showproblem.php?pid=6046 (2017 Multi-University Training Contest - Team ...
- 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 ...
- HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9
/* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...
- HDU 5726 GCD (2016 Multi-University Training Contest 1)
Time Limit: 5000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description Give y ...
- 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 ...
- HDU OJ 4334 Trouble 2012 Multi-University Training Contest 4
题目:click here 题意: 给定5组数据,每组数据选择一个数,看是否能找到5个数的和为零. 分析: 千万不要~~T~~ 普通线性查找: #include <iostream> #i ...
- hdu 6394 Tree (2018 Multi-University Training Contest 7 1009) (树分块+倍增)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6394 思路:用dfs序处理下树,在用分块,我们只需要维护当前这个点要跳出这个块需要的步数和他跳出这个块去 ...
- 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). 根 ...
- HDU 4938 Seeing People(2014 Multi-University Training Contest 7)
思路:根据出发时间把点往速度反方向移动 t*v的 的距离这样就可以当成 全部点一起出发,再把y轴上的点固定不动相当于x轴的点向(-v2,v1)方向移动 .可以把所有点映射到x轴上进行统计即可(要记住同 ...
随机推荐
- libtool
[从网上摘录的,忘了从哪摘的了] libtool常见于autoconf/automake,单独用的例子很少,所以我想仔细研究一下,为将来兄弟们看起来方便. 一.libtool的作用offer a ...
- 【转帖】Linux 桌面进化史
Linux 桌面进化史 https://www.oschina.net/news/109440/how-linux-desktop-grown 与之前认识到的一样 桌面最开始 是 施乐公司研发的. 后 ...
- [转帖]Vim全键盘操作
https://www.cnblogs.com/pzqu/p/11416436.html Vim脱离鼠标第一步 平时不可缺少的会用到vim,但是避免不了鼠标,事实上,省略鼠标是完全可以的,没有想像中那 ...
- Photon Server初识(六) --- 客户端与服务端消息传递
前一章客户端与服务端连接成功,现在需要前后端进行数据传递. 一.前端发送消息.在项目Scripts目录中新建脚本 TestSer.cs.并挂载到相机上 二.客户端发送数据给服务端.编辑客户端代码 Te ...
- jsp页面报错,各种错误码意思
基本原则: 2xx = Success(成功) 3xx = Redirect(重定向) 4xx = User error(客户端错误) 5xx = Server error(服务器端错误) 状态码 ( ...
- 【KMP】OKR-Periods of Words
[KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...
- rabbitmq消息队列,消息发送失败,消息持久化,消费者处理失败相关
转:https://blog.csdn.net/u014373554/article/details/92686063 项目是使用springboot项目开发的,前是代码实现,后面有分析发送消息失败. ...
- 利用ant-design封装react的地址输入组件
在上一节利用element-ui封装地址输入的组件留下了个尾巴,说react搭配ant-design封装一下地址输入的组件的.本来应该早早就完成的,但是由于这中间发生了一些事情,导致了突发性的换了工作 ...
- VS显示方法引用
菜单栏 工具->选项->文本编辑器->所有语言->CodeLens 勾上即可
- 验证组件FluentValidation的使用示例
官方文档:https://fluentvalidation.net/start#complex-properties 示例Demo:https://github.com/DavideYang125/F ...