题意:给出表长和待插入的元素,求每个元素的插入位置,散列函数为H(key)=key%TSize,解决冲突利用平方探测法(只考虑正向偏移)。

思路:同1145 Hashing - Average Search Time

代码:

#include <cstdio>
#include <cmath>
#include <unordered_map>
using namespace std;

bool isPrime(int n)
{
    ) return false;
    int sqr=(int)sqrt(n);
    ;i<=sqr;i++)
        ) return false;
    return true;
}

int main()
{
    int MSize,n,key;
    scanf("%d%d",&MSize,&n);
    while(!isPrime(MSize))
        MSize++;
    ]={false};//exist[i]为true表示位置i已经被占据了
    ];
    unordered_map<int,int> pos;//pos[val]存放val的位置
    ;i<n;i++){
        scanf("%d",&key);
        data[i]=key;
        ;
        for(;d<MSize;d++){
            int p=(key+d*d)%MSize;
            if(exist[p]==false){
                exist[p]=true;
                pos[key]=p;
                break;
            }
        }
        ;
    }
    ;i<n;i++){
        ) printf("-");
        else printf("%d",pos[data[i]]);
        ) printf(" ");
    }
    ;
}

1078 Hashing的更多相关文章

  1. 1078. Hashing (25)【Hash + 探測】——PAT (Advanced Level) Practise

    题目信息 1078. Hashing (25) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The task of this problem is simple: in ...

  2. PAT 1078 Hashing[一般][二次探查法]

    1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive integ ...

  3. pat 甲级 1078. Hashing (25)

    1078. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of t ...

  4. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  5. 1078 Hashing (25 分)

    1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive integ ...

  6. PAT甲题题解-1078. Hashing (25)-hash散列

    二次方探测解决冲突一开始理解错了,难怪一直WA.先寻找key%TSize的index处,如果冲突,那么依此寻找(key+j*j)%TSize的位置,j=1~TSize-1如果都没有空位,则输出'-' ...

  7. PAT 1145 1078| hashing哈希表 平方探测法

    pat 1145: 参考链接 Quadratic probing (with positive increments only) is used to solve the collisions.:平方 ...

  8. 1078. Hashing (25)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of this problem is simp ...

  9. PAT 1078. Hashing

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...

随机推荐

  1. thrift安装及常见问题

    一.安装thrift (macOS / Linux) 1. 下载thrift0.10.0源码 https://github.com/apache/thrift/releases/tag/0.10.0 ...

  2. angularjs1 自定义轮播图(汉字导航)

    本来想用swiper插件的,可是需求居然说要汉字当导航栏这就没办法了,只能自己写. directive // 自定义指令: Home页面的轮播图 app.directive('swiperImg', ...

  3. 虚拟主机(多站点配置)的实现--centos上的实现

    Apache中配置多主机多站点,可以通过两种方式实现 将同一个域名的不同端口映射到不同的站点(虚拟主机) 将同一个端口映射成不同的域名,不同的域名映射到不同的站点 两种方法可以同时存在,局域网通过   ...

  4. Git的add、commit、push命令

    简单的代码提交流程1.git status 查看工作区代码相对于暂存区的差别2.git add . 将当前目录下修改的所有代码从工作区添加到暂存区 . 代表当前目录3.git commit -m ‘注 ...

  5. @ResponseBody与@RestController的作用与区别

    在使用springmvc框架的时候,在处理json的时候需要用到spring框架特有的注解@ResponseBody或者@RestController注解,这两个注解都会处理返回的数据格式,使用了该类 ...

  6. 51nod1241 lis变形

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1241 1241 特殊的排序 题目来源: 摩根斯坦利的比赛题 基准时间限制 ...

  7. ES6相关文章

    1.https://www.cnblogs.com/xiaotanke/p/7448383.html (export ,export default 和 import 区别 以及用法)

  8. 010-对象——构造方法__construct析构方法__destruct使用方法 PHP重写与重载

    <?php /*抽象方法和抽象类 抽象类必须通过子类继承之后,才能实现实例化. 类中有抽象方法,必须声明抽象类. 如果是抽象类,可以没有抽象方法,但必须通过子类去继承之后,实现实例化 final ...

  9. 软工作业-四则运算(java实现)BY叶湖倩,叶钰羽

    四则运算生成器 BY-信安1班 叶湖倩(3216005170) 信安1班 叶钰羽(3216005171) 1. 项目介绍 源代码GitHub地址:https://github.com/yeyuyu/s ...

  10. L136

    Newly formed blood vessels may contribute to eye disease: studyA study of Northwestern University (N ...