#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct Hash
{
bool * Storage;
int MSize;
};
Hash * Creat(int MSize)
{
Hash *h=new Hash;
h->MSize=MSize;
h->Storage=new bool[MSize];
fill(h->Storage,h->Storage+h->MSize,false);
return h;
}
bool isPrim(int p)
{
int i=0;
if(p<2) return false;
for(i=2; i<=sqrt(p); i++)
{
if(p%i==0) return false;
}
return true;
}
int Prim(int n)
{
while(!isPrim(n))
{
n++;
}
return n;
}
int Hash_Fun(int key, int MSize)
{
return key%MSize;
}
int main(int argc, char** argv) {
int MSize,N;
scanf("%d %d",&MSize,&N);
MSize=Prim(MSize);
Hash *H=Creat(MSize);
for(int i=0; i<N; i++)
{
int tmp;
bool flag=false;
scanf("%d",&tmp);
for(int j=0; j<N; j++)
{
int pos=Hash_Fun(Hash_Fun(tmp,H->MSize)+j*j,H->MSize);
if(!H->Storage[pos])
{
H->Storage[pos]=true;
flag=true;
(i==N-1)?printf("%d",pos):printf("%d ",pos);
break;
}
}
if(flag) continue;
else
{
(i==N-1)?printf("-"):printf("- ");
}
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
09-散列1. Hashing (25).zip
共6个文件
win:1个
dev:1个
cpp:1个
需积分: 10 14 下载量 63 浏览量
2015-07-08
10:33:22
上传
评论
收藏 500KB ZIP 举报
温馨提示
http://blog.csdn.net/xkzju2010/article/details/46695007
资源推荐
资源详情
资源评论
收起资源包目录
09-散列1. Hashing (25).zip (6个子文件)
09-散列1. Hashing (25)
Makefile.win 1KB
09-散列1. Hashing (25).layout 82B
09-散列1. Hashing (25).exe 1.91MB
09-散列1. Hashing (25).dev 932B
main.cpp 1KB
main.o 71KB
共 6 条
- 1
资源评论
Ace_XK
- 粉丝: 305
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功