7-21 Hashing(25 分)

易康eCognition9.0分类|规则集和机器学习的方法的面向对象的多尺度分割分类 基于易康eCognition9.0软件的规则集和机器学习的方法的面向对象的多尺度分割分类 阅读详情
7-21 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 (≤10​4​​) 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 4
10 6 4 15

Sample Output:

0 1 4 -
code:
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct HTable{
    int *List;
    int Size;
};
typedef struct HTable* HashTable;
int prime[100000];
void is_Prime(){//筛选法求素数
    int i,j;
    for(i = 0; i < 100000; i++){
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for(i = 2; i < 100000; i++){
        if(prime[i]){
            for(j = i+i; j < 100000; j += i){
                prime[j] = 0;
            }
        }
    }
}
int NextPrime(int n){
   if(!prime[n]){//如果不是素数
      int i = n+1;
      while(!prime[i]){//一直加直到出现第一个素数
        i++;
      }
      return i;
   }
}

HashTable Creat(int n){
    HashTable H;//创建结构体并初始化
    int i;
    H = (HashTable)malloc(sizeof(struct HTable));
    H->Size = NextPrime(n);
    H->List = (int*)malloc(H->Size*sizeof(int));
    for(i = 0; i < H->Size; i++)
        H->List[i] = 0;
    return H;
}

int Insert(HashTable H,int num){
    int pos,i;
    pos = num % H->Size;
    for(i = 0; i <= H->Size && H->List[pos]; i++)//如果H->List[pos]这个点是0,则直接插入不执行循环,如果发现这个位置已经有了,则进行二次查找
        pos = (pos + 2*i + 1) % H->Size;
    if(i <= H->Size){//如果在哈希表大小范围内找到新位置,返回新位置
        H->List[pos] = 1;
        return pos;
    }
    else return -1;//如果在大小范围内找不着合适位置,返回-1
}

int main(){
    is_Prime();
    int i,m,n,num;//m是大小,n是所给元素个数,num是每次输入的元素
    int pos[10001];//记录哈希出来的位置
    HashTable H;
    scanf("%d%d",&m,&n);
    H = Creat(m);//创建一大小为m的哈希表
    for(i = 0; i < n; i++){
        scanf("%d",&num);
        pos[i] = Insert(H,num);//哈希
    }
    if(n){
        printf("%d",pos[0]);
        for(i = 1; i < n; i++){
            if(pos[i] == -1)printf(" -");//如果值是-1.输出-
            else printf(" %d",pos[i]);
        }
    }
    return 0;
}


【ROS2】手眼标定:moveit2_handeye_calib使用详解 moveit2_handeye_calib MoveIt2 官方的 手眼标定功能包,包含标定插件、图形化界面和示例程序。提供基于 ArUco/ChArUco 标定板的采集与求解功能。标定板下载aruco在线生成器。 阅读详情

相关推荐

AutoCAD2016安装破解教程

AutoCAD2016安装破解教程。本人亲自实验,破解成功,有效。以64位为例。 工具/原料   笔记本电脑 AutoCAD2016安装包 AutoCAD2016注册机(xf-adsk2016_x64.exe)链接:http://pan.baidu.com/s/1cAZQA windows7/8/8.1/10-32...

weixin_33804990的博客 1万+

pat 甲级 A1078 Hashing

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 beH(key)=key%TSizewhereTSizeis the maximum size of the hash table. Qua...

m0_51711089的博客 283

「大模型学习」(11)kv cache与vllm详解,一文读懂!

Key(键):表示上下文的特征。Value(值):表示上下文的内容。Query(查询):表示当前 token 的查询向量。AttentionQKVsoftmaxQKTdkVAttentionQKVsoftmaxdk​​QKT​V),每次生成一个新 token(比如下一个词),模型会再次查看之前的所有K和V,以计算当前 token 的注意力。问题:每次都重新计算之前的 K/V 很浪费!项目维度(简化)含义Q当前 token 的查询向量。

qq_43044037的博客 5422

PAT 1078 Hashing [平方探查法] [素数判断]

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 beH(key)=key%TSiz...

咸鱼夏の翻身观察记录 470

3DE重客户端安装

3DE重客户端安装

m0_48170265的博客 9544

STM32F4驱动海康工业相机实战:从PWM信号到精准触发拍照(附完整代码)

本文详细介绍了如何使用STM32F4开发板驱动海康工业相机,实现PWM信号精准触发拍照的完整方案。从硬件连接到PWM信号生成,再到相机触发配置与延迟补偿,提供了实战经验和完整代码,帮助开发者解决工业相机硬件触发中的关键问题。

weixin_33716941的博客 711

算法基础系列第二章——哈希表

对哈希表的理解与总结

weixin_52621323的博客 1026

15、z/OS 优化配置与迁移实践

本文详细探讨了z/OS环境的优化配置与迁移实践,涵盖DASD存储库管理、用户目录更新、环境更新意义以及不同场景下的迁移案例。通过单笔记本系统和服务器级机器的实例,展示了迁移流程和关键要点,包括DASD文件创建、设备映射更新、系统重启初始化以及数据备份等步骤。文章还总结了迁移过程中的注意事项,并展望了未来z/OS优化的发展趋势,为z/OS系统的稳定运行和高效管理提供了实用指导。

zzz56的博客 138

PAT-甲级 1145 Hashing - Average Search Time(哈希正向平方探测法的插入与查找)

Question The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average search time (the number of comparisons made to fin

qq_51738428的博客 325

Python爬虫实战:如何从Google Maps和OpenStreetMap抓取地理坐标数据

地点名称:地理位置的名称或地址。地理坐标:经度和纬度。类别信息:比如餐馆、商店、公园等。评论数据:如果可用,获取用户评论。本文介绍了如何使用Python爬虫从Google Maps和OpenStreetMap抓取地理坐标数据,并展示了如何存储和分析这些数据。通过实际的代码示例,您可以学习到如何处理不同类型的地图数据抓取任务,以及如何应对反爬虫机制。掌握这些技术后,您可以进行更广泛的地理数据分析,提供更有价值的地理信息服务。

2201_76125261的博客 1046

关于1EDI3033AS驱动芯片误触发DESAT保护的问题

驱动参数匹配:检查门极电阻(Rg)是否合理,过小的Rg可能加剧dv/dt干扰,而过大的Rg会增加开关损耗。SiC驱动欠压故障分为上桥故障和下桥故障,利用上位机,配置软件后上桥故障使得TestC为1,下桥故障使得TestB为1。500V母线电压,10k载频,200hz电频率,假负载大电流闭环测试时,相电流高于60A之后报SiC驱动故障。600V母线电压,10k载频,200hz电频率,接水冷,假负载350A电流闭环测试。750V母线电压,10k载频,200hz电频率,接水冷,假负载350A电流闭环测试。

小幽余生不加糖 615

PAT甲级 1078 Hashing (25 分)(二次方探查法)

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 ...

qq_29762941的博客 494

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

7-21 Hashing (25分)(平方探查法)

题目: 分析: num[i]用于存放数值 首先要判断输入的初始m是否为素数,如果不是素数,需要将m增加到素数 确定了m之后,判断pos = num[i] % m这个位置在hashTable中是否已经被访问了,如果vis[pos]为false,说明此位置未被访问直接输出即可,如果为true,说明此位置已经被访问了,之后运用平方探查法找合适的位置,具体的做法是 nexPos = (pos + j*...

Joker的博客 397

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

1078 Hashing (25 分)

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 t...

weixin_43482621的博客 252

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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 %

ForLearning 1117

PAT (Advanced Level) Practice - 1145 Hashing - Average Search Time(25 分)

题目链接:点击打开链接 题目大意:略。 解题思路:平方探测法处理哈希表,但是该题只能正增长:with positive increments only。即,hi=(h(key)+i*i)%m (0 ≤ i ≤ m-1),注意:类似样例中“15”是插入不进的这种数,理论上应该是 [0,size-1] == size 次,但是这里还要额外 +1 次,因为这 1 次是出于 di==siz...

528

(c语言)Hashing (25分)

关于数据结构Mooc后的每一道答案 基本我都已经给出了详解 希望能对大家有所帮助 收藏一下也是方便大家查找吧 希望大家一起进步! (c语言)浙大数据结构Mooc作者答案集 原题谷歌翻译 闲谈 Where were you, when I was trying to make a move Told them I would make it, they didn’t believe it Even if dont make it,thats all my effort without regre

Love 6's Private Blog 521

1145 Hashing - Average Search Time (25 分)

1145Hashing - Average Search Time(25分) The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another s...

weixin_30828379的博客 89

字节面试题用python实现Bigram hashing

使用Python实现Bigram Hashing 在自然语言处理(NLP)领域,文本数据的处理和分析是一个重要的任务。Bigram模型是文本分析的一种基本方法,它通过考虑文本中相邻两个词的组合来捕捉上下文信息。本篇文章将探讨Bigram模型及其Hashing实现,提供Python代码示例,并强调其在数据处理和分析中的重要性...

weixin_28772667的博客 205

PAT 1078. Hashing (25)

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 de...

dengkonglou4529的博客 81

PTA—11-散列4 Hashing - Hard Version (30分)

代码有问题 先存着#include "StdAfx.h" #include #include #include #include using namespace std; #define MAX 1000 struct HashNode { int seq; int Key; int indegree; friend bool operat

as14569852的博客 1179

11-散列4 Hashing - Hard Version (30 分)

Given a hash table of sizeN, we can define a hash function(. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequence of i...

weixin_30782331的博客 138

7-18 Hashing - Hard Version

7-18Hashing - Hard Version(30 分) Given a hash table of sizeN, we can define a hash function . Suppose that the linear probing is used to solve collisions, we can easily obtain the status of ...

weixin_30496751的博客 722

pat1078. Hashing (25)

1078. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of this problem is simple: insert a sequence of distinct positive integ...

weixin_30572613的博客 72

PAT 09-散列1. Hashing (25)

09-散列1. 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 defi...

weixin_30247307的博客 91

pat09-散列1. Hashing (25)

09-散列1. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue The task of this problem is simple: insert a sequence of distinct positive inte...

weixin_30793643的博客 85
上一篇: 7-20 电话聊天狂人(25 分) (哈希)
下一篇: 7-22 朋友圈(25 分) (并查集)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址