博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1078 Hashing (25 分)
阅读量:4977 次
发布时间:2019-06-12

本文共 1892 字,大约阅读时间需要 6 分钟。

1078 Hashing (25 分)

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSize where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions.

Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user.

Input Specification:

Each input file contains one test case. For each case, the first line contains two positive numbers: MSize (104​​) and N (MSize) which are the user-defined table size and the number of input numbers, respectively. Then N distinct positive integers are given in the next line. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the corresponding positions (index starts from 0) of the input numbers in one line. All the numbers in a line are separated by a space, and there must be no extra space at the end of the line. In case it is impossible to insert the number, print "-" instead.

Sample Input:

4 410 6 4 15

Sample Output:

0 1 4 - 思路:   
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int findPrim(int mSize){ for(int num=mSize;;num++) { bool flag=true; if(num==1) continue; for(int i=2;i<=sqrt(num);i++) { if(num%i==0) flag=false; } if(flag) { return num; } }}int main(){ int mSize,n; scanf("%d%d",&mSize,&n); int len=findPrim(mSize>n?mSize:n); int a[len]; //cout<
<
result; for(int i=0;i

 

 

转载于:https://www.cnblogs.com/zhanghaijie/p/10329759.html

你可能感兴趣的文章
C# 中的委托和事件
查看>>
CSS基础学习 17.CSS动画
查看>>
ATM机
查看>>
java反射
查看>>
js表单反显
查看>>
浪潮之巅阅读笔记二
查看>>
CSS内嵌样式实现打字效果
查看>>
从 HTTP 到 HTTPS 再到 HSTS
查看>>
JavaScript进阶 从实现理解闭包
查看>>
oracle数据库关闭了打开数据库
查看>>
warning: the `gets' function is dangerous and should not be used.(转)
查看>>
进阶之路 - 000 目录
查看>>
asp.net实现 EXCEL数据导入到数据库功能
查看>>
Java之内部类
查看>>
NOIP201502扫雷游戏
查看>>
Unity编辑器扩展chapter1
查看>>
微信小程序 Image 图片实现宽度100%,高度自适应
查看>>
VNC Viewer
查看>>
我用windows live Writer 写个日志试试看
查看>>
线程安全日期格式化操作的几种方式
查看>>