1078 Hashing (25 point(s))

实验7:机器学习油田产量预测-代码数据-完整代码数据可直接运行-计算机毕设 阅读详情

1078 Hashing (25 point(s))

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

翻译:Quadratic probing(with positive increments only) 正向平方探测法 

参考链接:https://blog.youkuaiyun.com/qq_37142034/article/details/87903983

体会哈希思想(哈希表)的应用。

特别的坑:注意到输入最大为1e4,因此应当至少能够判断出大于1e4的最小素数。由于我这里用的是素数筛法,我最初习惯性地将数组大小开为1e4+7,由此可以使用素数筛法可以筛选到的最大素数范围是2~1e4+6,而恰巧比10000大的最小素数是1e4+7,导致case#3和case#4一直不能通过(15分)。

#include<iostream>
using namespace std;
const int N = 10013;
bool mark[N]={false};
int prime[N];
int ht[N];
int index = 0;
void init(){
	for(int i=2;i<N;i++){
		if(mark[i]) continue;
		for(int j=i*i;j<N;j=j+i){
			mark[j]=true;
		}
	}
	for(int i=2;i<N;i++){
		if(!mark[i]) prime[index++]=i;
	} 
}
int main(void){
	init();
	int M,N,size,key;
	cin>>M>>N;
	for(int i=0;i<index;i++){
		if(prime[i]>=M){
			size = prime[i];break;
		} 
	} 
	for(int i=0;i<size;i++) ht[i]=-1;
	for(int i=0;i<N;i++){
		cin>>key;
		if(i!=0) cout<<" ";
		int pos = key%size;
		if(ht[pos]==-1){//hash表该项为空 
			ht[pos]=key;
			cout<<pos;
		}
		else{//发生冲突,线性平方探测
			bool flag =false;
			for(int i=1;i<=size-1;i++){
				int npos = (key+i*i)%size; 
				if(ht[npos]==-1){
			 		cout<<npos;
					ht[npos]=key;
			 		flag=true;
					break;
				}
			}
			if(!flag) cout<<"-";
		}
	}
	return 0;
}

 

大模型LoRA微调调参的实战技巧(持续更新) 本文主要介绍了大模型LoRA微调调参的实战技巧,希望对学习大语言模型的同学们有所帮助。 文章目录 1. 前言 2. 实战技巧 阅读详情

相关推荐

高速PCB设计中的信号完整性挑战:回损、插损与串扰的深度解析

本文深入探讨了高速PCB设计中的信号完整性挑战,重点分析了回损、插损与串扰三大关键问题。通过实际案例和专业技术解析,提供了降低回损的阻抗控制技巧、减少插损的板材选择建议以及抑制串扰的布线策略,帮助工程师应对5G和AI芯片时代的高速信号传输需求。

websocket5live的博客 265

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 %

大胖子狗的博客 507

T265摄像头插着开机后,需要重新插拔才能正常启动

T265摄像头插着开机后,需要重新插拔才能正常启动

qq_35598561的博客 1080

【1078】Hashing (25 分)

#include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<algorithm> #include<map> #include<vector> #inclu...

发现问题,并解决问题,批判性思维 558

STM32+A4988控制步进电机

基于A4988芯片驱动42步进电机,在STM32F1上进行测试,最高可以实现16细分。

个人博客 4万+

C语言新手必练:10个实战小项目带你快速上手(附完整代码)

本文为C语言初学者精选10个实战项目,从基础的温度转换器到高级的迷宫求解算法,涵盖输入输出、条件判断、循环控制、数组操作等核心知识点。每个项目配有完整代码和详细解析,帮助新手通过实践掌握编程思维,特别适合刚学完语法但缺乏实战经验的学习者。

weixin_29208077的博客 748

PAT(甲级)1078 Hashing (25point(s))

题目 题目链接 思路 先判断原题hash位置有没有被占用,如果被占用,就进行二次平方探查; 代码 #include <iostream> #include <string> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int maxn = 1e4 + 10; bool flag[maxn]; bool isPrime(in

hjyp的博客 185

基于DINO自监督学习对YOLO11 Backbone进行预训练

这PoolHead将获取前一层的输出并应用卷积,然后应用自适应平均池化以将特征图的空间维度减小为固定且一致的大小(1x1)。这是必需的,因为否则空间维度会根据输入的大小而变化,这将使将 DINO 头部附加到主干变得困难,因为它需要固定的输入大小。在本指南中,我们将介绍如何使用 Lightly 使用 DINO 预训练 YOLO 11主干,以及如何将其重新加载到 Ultralytics 中进行微调。您可以使用不同的大小,例如,640这与 YOLO 中的默认图像大小更一致,但它也会在训练期间消耗更多 VRAM。

如果想成为中心,那么就到中心去吧。 1014

Pat(Advanced Level)Practice--1078(Hashing)

Pat1078代码 题目描述: 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 defin

奋起的Coder。。。 1145

道路施工检测 (construction) - 基于Mapillary Vistas数据集的YOLOv11目标检测及UI界面实现

目标检测是计算机视觉的重要任务,目标是识别图像中的目标物体类别及其位置(用边界框表示)。两阶段检测器:如Faster R-CNN,准确度高但速度较慢单阶段检测器:如YOLO系列、SSD,速度快且精度相对较好,适合实时场景数据量:约25,000张高分辨率街景图标注类型:语义分割、实例分割、多类别检测类别示例:construction, road, car, person, traffic sign等格式:COCO风格JSON标注。

YOLO 497

手把手教你用ESP32-S3打造智能聊天机器人-立创实战派

本文将详细介绍如何利用立创ESP32-S3开发板,烧录小智AI程序,快速实现一个功能强大的聊天机器人。

举世誉之而不加劝,举世非之而不加沮,定乎内外之分,辩乎荣辱之境,斯已矣。 9922

1078 Hashing (25 point(s)) 笔记

原题连接 Quadratic probing 平方探查法 中文名为平方探查法。用于解决hash的collision。有算法笔记书的打开讲hash那一节的,曾经提到过。(忘了的活该卡一下午呜呜呜) 现在想想还是好气,以为那个词不重要(主要是看不懂)愣是卡了2小时…… 它的计算公式为 ...

fire_for_you的博客 273

基于 Langchain 开发一个完整的支持多轮数据分析(直连 mysql 数据,多表综合分析 SQL 取数,数据分析,报表生成)ChatBI 系统(前后端完整实现源代码)

ChatBI系统开发摘要 本文介绍了基于Langchain的多轮数据分析ChatBI系统开发方案。该系统支持MySQL数据库连接,提供多表分析、SQL查询、数据分析和报表生成功能。系统采用前后端分离架构:前端使用React+Ant Design+ECharts实现交互界面;后端基于FastAPI搭建服务,集成Langchain处理自然语言到SQL的转换;核心技术栈还包括SQLAlchemy、Pandas和Matplotlib。 系统核心模块包括: 数据库连接层:使用SQLAlchemy管理MySQL连接 L

AI天才研究院 816

1078 Hashing (25point(s))

1078 Hashing (25point(s)) 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 s

佳迪斯的博客 114

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

1078 Hashing (25 point(s))

题解 Quadratic probing 二次探测  处理冲突的方法: 开放定址法 Hi=(H(key)+di) MOD m i=1,2,...,k(k&lt;=m-1) 其中m为表长,di为增量序列 如果di值可能为1,2,3,...m-1,称线性探测再散列。 如果di取值可能为1,-1,2,-2,4,-4,9,-9,16,-16,...k*k,-k*k(k&lt;=m/2) 称二次探...

徐伯莱 319

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

1078 Hashing (25 point(s))

1078.哈希

Bonstoppo 302

1078 Hashing (25point(s)) - C语言 PAT 甲级

1. 输入的 Msize 若不是素数,需要重新赋值为第一个比它大的素数 2. 平方探测法 index = (key + i * i) % size

有三只土豆 153

1078 Hashing (25 point(s)) PAT甲级

1078 Hashing (25 point(s)) hash 题目 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

neko的博客 135

PAT A1078 Hashing (25point(s))

题目链接 注意点:1.判断素数时别忘了1不是素数也不是合数。 2.冲突处理公式是new position=(X+i*i)%msize。(i=1,2,3…) #include<cstdio> #include<math.h> int hashtable[10001]; bool is_prime(int n){//判断是否为素数 if(n<=1) return ...

皮皮瓜的博客 155

PAT----A1078 Hashing (25point(s))

A1078 Hashing (25point(s)) 记录一下平方探测这个小知识点。 题意 根据平方探测算法模拟哈希操作,能插入的输出插入的位置,否则输出 - 思路 直接模拟。注意size如果不是素数则选择下一个素数。 总结 平方探测算法:(x+i^2)%size Sample Input: 4 4 10 6 4 15 Sample Output: 0 1 4 - #include"bits/...

qq_43578870的博客 171

PAT_甲级_1078 Hashing (25point(s)) (C++)【哈希表/平方探测法】

1,题目描述 Sample Input: 4 4 10 6 4 15 Sample Output: 0 1 4 - 题目描述 2,思路 3,AC代码

&再见萤火虫&的博客 441

1145 Hashing - Average Search Time (25 point(s))

1145Hashing - Average Search Time(25point(s)) 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 inte...

coderwait 203

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

SourDumplings的博客 250

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的博客 493

PAT_甲级_1145 Hashing - Average Search Time (25point(s)) (C++)【哈希表/平方正向探测法】

1,题目描述 Sample Input: 4 5 4 10 6 4 15 11 11 4 15 2 Sample Output: 15 cannot be inserted. 2.8 2,思路 3,AC代码 4,解题过程 第一搏 #include<bits/stdc++.h> using namespace std; int ...

&再见萤火虫&的博客 409

PAT B1078 字符串压缩与解压 (20point(s))

文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符没有重复,就原样输出。例如 aba 压缩后仍然是 aba。 解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。 本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母和空...

qq_42347617的博客 226

PAT B1084 外观数列 (20point(s))

外观数列是指具有以下特点的整数序列: d, d1, d111, d113, d11231, d112213111, ... 它从不等于 1 的数字 d 开始,序列的第 n+1 项是对第 n 项的描述。比如第 2 项表示第 1 项有 1 个 d,所以就是 d1;第 2 项是 1 个 d(对应 d1)和 1 个 1(对应 11),所以第 3 项就是 d111。又比如第 4 项是 d113,其描述就是 ...

qq_42347617的博客 266
上一篇: 1047 Student List for Course
下一篇: 1076 Forwards on Weibo (30 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值