题意:给出表长和待插入的元素,求每个元素的插入位置,散列函数为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. lucene学习-1 - 准备工具

    需要准备的内容: jdk 1.7 eclipse Kepler lucene 4.10.2 luke 4.10.2 以及一些txt文档 其他的不需多说,只简要介绍下luke. 以下内容来自百度百科: ...

  2. Angularjs注入拦截器实现Loading效果

    angularjs作为一个全ajax的框架,对于请求,如果页面上不做任何操作的话,在结果烦回来之前,页面是没有任何响应的,不像普通的HTTP请求,会有进度条之类. 什么是拦截器? $httpProvi ...

  3. 包嗅探和包回放 —tcpdump、tcpreplay--重放攻击

    攻击方式:tcpdump 进行嗅探,获取报文消息:然后用tcpreplay回放攻击 arp欺骗可以使用 arpspoof kali linux有这三个工具 转载地址https://www.cnblog ...

  4. Selenium with Python 002 - 快速入门

    一.简单实例演示 1.创建 python_org_search.py: #!/usr/bin/env python from selenium import webdriver from seleni ...

  5. 对CSS了解-选择器权重

    <style type="text/css"> div.ui_infor p {font-size: 16px;} .ui_infor p {font-size: 14 ...

  6. CSS:Tutorial one

    1.Three Ways to Insert CSS External style sheet Internal style sheet Inline style External Style She ...

  7. Android 进阶11:进程通信之 ContentProvider 内容提供者

    学习启舰大神,每篇文章写一句励志的话,与大家共勉. When you are content to be simply yourself and don't compare or compete, e ...

  8. Golang调用windows下的dll动态库中的函数

    Golang调用windows下的dll动态库中的函数 使用syscall调用. package main import ( "fmt" "syscall" & ...

  9. Java局域网对战游戏、天气预报项目

    功能 1.天气预报 2.局域网对战 展示  java学习群669823128   部分源码 package game.weather; import java.util.HashMap; public ...

  10. Image Pyramid (二)

    上一篇文章里,我们介绍了图像金字塔的基本原理,就是一种分层次的下采样.这篇文章里我们简单介绍一下图像金字塔的一种应用,image blending.利用图像金字塔做 image blending,可以 ...