Cuckoo for Hashing
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2719
#include <stdio.h>
#include <string.h>
const int N=;
using namespace std;
int a[N],b[N],f[N];
int main()
{
int n1,n2,m,o=;
while(~scanf("%d %d %d",&n1,&n2,&m))
{
o++;
int flag1 = ,flag2 = ;
if (n1==&&n2==&&m==)
break;
memset(a,-,sizeof(a));
memset(b,-,sizeof(b));
for (int i = ; i < m; i++)
scanf("%d",&f[i]);
int t1,t2,tt;
for (int i = ; i < m; i++)
{
tt = f[i];
while()
{
t1 = tt%n1;
if (a[t1]==-)
{
a[t1] = tt;
flag1 = ;
break;
}
else
{
int temp = a[t1];
a[t1] = tt;
t2 = temp%n2;
if (b[t2]==-)
{
b[t2] = temp;
flag2 = ;
break;
}
else
{ tt = b[t2];
b[t2] = temp;
flag2 = ; }
}
} }
printf("Case %d:\n",o);
if (flag1)
{
printf("Table 1\n");
for (int i = ; i < n1; i++)
{
if (a[i]!=-)
printf("%d:%d\n",i,a[i]); }
}
if (flag2)
{
printf("Table 2\n");
for (int i = ; i < n2; i++)
{
if (b[i]!=-)
printf("%d:%d\n",i,b[i]);
}
} }
return ;
}
Cuckoo for Hashing的更多相关文章
- Cuckoo for Hashing(hash)hunnuoj
Problem B:Cuckoo for HashingAn integer hash table is a data structure that supports insert, delete a ...
- 中国海洋大学第四届朗讯杯高级组 I Cuckoo for Hashing
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2719&cid=1203 题意 :意思就是哈希来的,具体大意就是说有两个哈希表,然后有这样 ...
- HNU 13064 Cuckoo for Hashing解题报告 North America - East Central 2013
题目大意:使用两个哈希表来解决哈希冲突的问题.假如现在有两个哈希表分别为:H1,H2 ,大小分别为:n1,n2:现有一数据X需要插入,其插入方法为: 1.计算index1 = X MOD N1, 若 ...
- Cuckoo for Hashing_双哈希表
问题 B: Cuckoo for Hashing 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 12[提交][状态][讨论版] 题目描述 An integer hash ta ...
- 2014 UESTC 暑前集训队内赛(2) 部分解题报告
B.Cuckoo for Hashing 模拟题. 代码: #include <iostream> #include <cstdio> #include <cstring ...
- HDU 1672 Cuckoo Hashing
Cuckoo Hashing Description One of the most fundamental data structure problems is the dictionary pro ...
- BloomFilter 与 Cuckoo Filter
BloomFilter 与 CuckooFilter Bloom Filter 原理 Bloom Filter是一种空间效率很高的随机数据结构,它的原理是,当一个元素被加入集合时,通过K个相互独立的H ...
- Cuckoo hash算法分析——其根本思想和bloom filter一致 增加hash函数来解决碰撞 节省了空间但代价是查找次数增加
基本思想: cuckoo hash是一种解决hash冲突的方法,其目的是使用简单的hash 函数来提高hash table的利用率,同时保证O(1)的查询时间 基本思想是使用2个hash函数来处理碰撞 ...
- Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
A hash function that maps names to integers from 0 to 15. There is a collision between keys "Jo ...
随机推荐
- C#的一些知識點
不能將屬性以ref或out的方式傳遞 看上去屬性和字段差不多,可是屬性本質上是個方法,并不是真正指向一個内存位置,所以不能像字段那樣能以ref或out方式傳遞. Lookup運行一個鍵對應多個值,但無 ...
- zxing 生成条形码
private Bitmap Out1DImg() { // 1.设置条形码规格 EncodingOptions encodeOption = new EncodingOptions(); encod ...
- Typescript编译设置
TypeScript MSBuild编译选项,用记事本打开工程文件,进行修改,如<TypeScriptGeneratesDeclarations>true</TypeScriptGe ...
- js 计算是今天多少周
/** * 判断年份是否为润年 * * @param {Number} year */ function isLeapYear(year) { return (year % 400 == 0) || ...
- 文本框、评论框原生js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- isinstance、issubclass、反射
一.isinstance.issubclass # isinstance(obj, cls) 检查obj是否是cls的对象 class A(object):pass a = A() print(isi ...
- 如何在Ubuntu16.04 中安装Linux, Nginx, MySQL, PHP (LEMP 栈)
介绍 LEMP 栈是用来开发动态网页和web 应用程序的一系列软件集合,LEMP描述的是Linux操作系统,Nginx web 服务器,以及后端数据存储MySQL/MariaDB数据库和服务器端动态脚 ...
- python的转义字符及用法详解
在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符. Python3.7 的官方文档中列出的所支持的转义字符,如下表: 中文版: 注:\oyy 应该是 \0yy 另外 :\e 和 \0 ...
- 基本数据类型:字符串(str)
一.字符串的定义和创建 字符串是一个有序的字符的集合,用于存储和表示基本的文本信息,' '或'' ''或''' '''中间包含的内容称之为字符串,总之加了引号的字符都被认为是字符串! 创建: > ...
- Spring MVC 单元测试Demo
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations={" ...