随笔分类 -  散列表

摘要:内部赛遇到这道题SDUT_2369,map写TLE。话说校内OJ很奇芭的把队友的判成AC,把我的判成TLE。最后队长总结说这是人品问题。。。汗 =_=///赛后用hash写了一下,关键要处理冲突,用挂链法写的。最后自己看了一下,怎么看怎么像邻接表。或许可以把这个题改一下弄个不错的图论题,哈poj 1235 + ms, sdutoj 578 + ms。我们的服务器还是很给力的。渣代码:View Code 1 #include <vector> 2 #include <list> 3 #include <map> 4 #include <set> 5 阅读全文
posted @ 2012-03-24 20:06 AC_Von 阅读(318) 评论(0) 推荐(0) 编辑
摘要:据说使折叠法:int hashcode(int *v, int k) { int i, p = 0; for(i = 0; i < k; ++i) { p = ((p << 2) + (v[i] >> 4))^(v[i] << 10); } p %= MOD; if(p < 0) p += MOD; return p;}ELFhash UNIX系统处理字符串使用的哈希//UNIX系统使用的哈希int ELFhash(char *key) { unsigned long h = 0; while (*key) { ... 阅读全文
posted @ 2012-03-14 23:26 AC_Von 阅读(313) 评论(0) 推荐(0) 编辑
摘要:Hash思想,因为题目要求第K大的数,可能很多人会想到先从小到大排序,然后找到第k个数。但是,注意,|xi - xj|可能会出想重复,也就是说排好序还得处理重复。Hash的大体思路是:将|xi - xj|作为一个hash数组的下标,如果hash[|xi - xj|]为空则hash[|xi - xj|]++;查找第k大时直接遍历一遍hash数组就行;代码:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 2007;int a[N/2]; 阅读全文
posted @ 2011-08-20 10:17 AC_Von 阅读(271) 评论(0) 推荐(1) 编辑
摘要:这两题的思路都是将等式化成左右两部分,用一个hash数组,先把左边的结果存起来,然后计算右边的结果直接寻址就行,不过,HDU那道题要注意剪枝,如果系数全为正或者全为负则直接输出0,POJ那道题hash函数定义成char型的,否则会超内存。。 HDU_1496 Equations:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 2000009;int hash[N];int main(){ //freopen("data.i 阅读全文
posted @ 2011-08-20 09:03 AC_Von 阅读(201) 评论(0) 推荐(0) 编辑
摘要:Crazy Search Time Limit: 10000/5000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 772Accepted Submission(s): 289Problem DescriptionMany people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in 阅读全文
posted @ 2011-08-07 21:37 AC_Von 阅读(1513) 评论(1) 推荐(0) 编辑
摘要:这题的数据有点问题,给的N个数里边最大的数是多少不知道,直接猜了个数用hash做了,居然1A了。。。。#include <stdio.h>#include <string.h>#define N 100007int hash[N];int main(){ int n, i, a; while(scanf("%d", &n) != EOF) { memset(hash, 0, sizeof(hash)); int max = -1; while(n--) { scanf("%d", &a); if(a > ma 阅读全文
posted @ 2011-08-06 08:24 AC_Von 阅读(229) 评论(0) 推荐(0) 编辑
摘要:SnowflakeSnowSnowflakesTime Limit: 4000MSMemory Limit: 65536KTotal Submissions: 18478Accepted: 4770DescriptionYou may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowfl 阅读全文
posted @ 2011-07-23 17:27 AC_Von 阅读(356) 评论(0) 推荐(1) 编辑