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 ...
随机推荐
- CSS居中布局方案
基本结构 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- Android中Adapter和Bridge模式理解和应用
一 Adapter模式 意图: 将一个类的接口转换成客户希望的另外一个接口. Adapter模式使得原本由于接口不兼容而不能在一起工作的那些类可以在一起工作. 适用性: 使用一个已存在的类,而它的接口 ...
- 在把table表格中的数据导出到Excel的时候,以科学计数法显示位数多的数字时怎么解决?
sbHtml.AppendFormat("<td> {0}</td>", data[i].IDcard.ToString()); sbHtml.Append ...
- 奇怪的print progname ":\n"日志
[root@xxxxxxxx /home/ahao.mah] #tail /var/log/messages -f Feb 10 10:01:01 csaccurate-49-5011 } Feb 1 ...
- SQL上门
学习这个 介绍:SQL 是用于访问和处理数据库的标准的计算机语言.结构化化查询语言! SQL可以分为两大部分:数据操作语言(DML)和数据定义语言(DDL) 数据操作语言:select.update. ...
- RHEL6 配置Yum库
在/mnt目录下创建子目录“/cdrom”(用于将iso文件挂载到此目录下) 镜像状态确定为“已连接”(“已连接”未勾选的情况下无法获得iso文件) 配置自动挂载文件 (系统开机时会主动读取“/etc ...
- Python中的可迭代对象/迭代器/For循环工作机制/生成器
本文分成6个部分: 1.iterable iterator区别 2.iterable的工作机制 3.iterator的工作机制 4.for循环的工作机制 5.generator的原理 6.总结 1.i ...
- 团体程序设计天梯赛-练习集L1-006. *连续因子
L1-006. 连续因子 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个正整数N的因子中可能存在若干连续的数字.例如630 ...
- 7 numpy 傅里叶,提取图片轮廓
任务:提取照片中轮廓 本次处理图片:我的女神之一 江一燕 导入模块: #jyy.show() 会打开本地图片浏览器 使用傅里叶反转 获取实部,舍弃虚部 去除小数部分 将一维数 ...
- scrapy——3 crawlSpider——爱问
scrapy——3 crawlSpider crawlSpider 爬取一般网站常用的爬虫类.其定义了一些规则(rule)来提供跟进link的方便的机制. 也许该spider并不是完全适合您的特定网 ...