查找练习 hash——出现过的数字

哈希表等查找成功和查找不成功的平均查找长度(线性探测法+链地址法) 最近刷面试题遇到哈希表求平均查找长度的题,已经忘了,来记录下 Question1: 将关键字序列(7、8、30、11、18、9、14)散列存储到散列表中。散列表的存储空间是一个下标从0开始的一维数组,散列函数为:      H(key) = (keyx3) MOD 7,处理冲突采用线性探测再散列法,要求装填(载)因子为0.7。 (1) 请画出所构造的散列表。 (2) 分别计算等概率情况下查找成功和查找不成功的平均查找长度。 Ans: (1).首先明 阅读详情

查找练习 hash——出现过的数字

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

有一个数据字典,里面存有n个数字(n<=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量的问题,小明找到了善于编程的你,希望你可以帮他解决这个问题。

Input

输入数据只有一组!
第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。
接着n行代表字典中的n个数字。
最后m表示要查询的数字。
Output

如果某个数字存在,则输出YES,否则输出NO

Example Input

5 3
1
2
3
4
5

5
4
10
Example Output

YES
YES
NO
Hint

Author

赵利强

基于桶排的思想,利用数组下标存储,然后查找。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 123456
int a[MAXN];
int main()
{
    int n, m, b;
    scanf("%d %d", &n, &m);
    memset(a, 0, sizeof(a));//全部清零
    for(int i=0;i<n;i++)
    {
        scanf("%d", &b);
        a[b] = 1;//用下标表示输入的数字,将数组标记为1
    }
    while(m--)
    {
        scanf("%d", &b);
        if(a[b])//所要查找的数字在数组下标中存在
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
纸片 C++ 现在给定l(此为小写字母l)和r, 小明拿到了r−l+1张纸片,上面分别写着l,l+1,l+2…r-1,r,现在把它们按顺序连在一起看,变成l(l+1)(l+2)…(r-1)r,例如l=2,r=6连在一起后得到23456,小明 现在想知道这个数是不是9的倍数。注意:粗心的老师并不能保证每次询问的l和r一定满足l<=r,所以写程序要小心哦~ 【数据范围】 对于30%的数据, 1≤l,r≤10 对于50%的数据, 1≤l,r≤10^6 对于100%的数据, 1≤T≤10000,1≤l,r≤10^12 输入 阅读详情

相关推荐

Imatest-Star模块(西门子星图)

星图分析指南:基于ISO12233标准的MTF测试方法,通过放射状射线和正弦灰度变化评估相机SFR性能。

weixin_64706696的博客 1589

哈希查找方法经典题型

查找练习 hash——出现过的数字 Time Limit: 1000MS Memory limit: 65536K 题目描述 有一个数据字典,里面存有n个数字(n<=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量的问题,小明找到了善于编程的你,希望你可以帮他...

1197

Python实战:用Realsense D435和睿尔曼机械臂完成手眼标定的5个关键步骤

本文详细介绍了使用Python、Realsense D435深度相机与睿尔曼机械臂进行手眼标定的完整实战流程。文章将过程拆解为环境搭建、数据采集、核心计算、结果验证和精度优化五个关键步骤,重点剖析了数据采集的黄金法则、常见错误排查以及如何将标定结果集成到视觉抓取程序中,旨在帮助开发者实现毫米级精度的视觉引导机器人系统。

weixin_29103191的博客 326

哈希表(开放寻址法)

#include<iostream> #include<cstring> using namespace std; const int N=200003; int h[N],null=0x3f3f3f3f; int find(int x) { int k=(x%N+N)%N; while(h[k]!=null&&h[k]!=x) { k++; if(k==N) k=0; } return k; }...

qq_56017552的博客 581

Unity游戏开发架构选择:ECS与OOP的性能、场景与实战对比

在游戏开发中,架构选择直接影响项目的性能与可维护性。面向对象编程(OOP)以对象为中心封装数据与行为,符合人类直觉,便于快速原型开发。然而,随着实体数量激增,其内存访问随机、缓存不友好的问题会引发性能瓶颈。实体组件系统(ECS)则采用数据导向设计,将纯数据组件与逻辑系统分离,通过连续内存布局和并行处理,极大提升了CPU缓存命中率与多核利用率。这种架构尤其适用于需要处理大规模单位移动、状态效果计算等模拟密集型场景,能有效实现数据局部性和零GC分配。对于Unity开发者而言,理解ECS在数据驱动、并行化方面的优

weixin_33981932的博客 334

PPO算法详解:基于CartPole-v1的强化学习实现

PPO算法详解:基于CartPole-v1的强化学习实现

m0_54720701的博客 872

1096

题目网址:NSWOJ-1096-多项式相加; 1096 - 多项式相加 时间限制:1秒 内存限制:128兆 题目描述 一条单链表可以表示一个一元多项式,每个节点包含三个域:指数、系数和后继节点(指针或引用)。 表示多项式3X4-6X2+5X-10的单链表如图所示。给定两个多项式,实现两个多项式相加算法。 输入 第一行输入包含两个整数m,n 后续为

张松超的博客 2545

基于英特尔 RealSense D455 相机实现裂缝尺寸以及深度测量

D455 相机可用于对这些零部件进行高精度的表面检测,快速准确地测量裂缝的尺寸和深度,实现自动化的质量控制和缺陷筛查,提高生产效率和产品质量。D455 相机能够对焊缝表面进行细致扫描,测量焊缝的宽度、深度以及焊缝表面的不规则程度等参数,帮助检测焊缝是否存在缺陷,如未焊透、焊瘤等,为焊接质量的评估和改进提供数据支持。:RGB 传感器采用全局快门,并且其视场与深度视场相匹配,能够提供更出色的 RGB 图像质量,以及深度图像和 RGB 图像之间的更好对应性,从而可提高扫描质量。可以看出宽度和高度都是十分准确的。

qq_53545309的博客 1723

查找练习 hash——出现过的数字(最简单的哈希)

Problem Description 有一个数据字典,里面存有n个数字(n&lt;=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量的问题,小明找到了善于编程的你,希望你可以帮他解决这个问题。   Input  输入数据只有一组! 第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。...

ACMerdsb的博客 400

RK3588在线更新系统内核的方法

《RK3588设备在线升级系统内核方法》 本文介绍了RK3588设备在线升级系统内核的简易方法。通过将新内核文件boot.img拷贝至目标主机后,使用dd命令配合关键参数(fsync确保写入磁盘、notrunc避免截断分区)进行安全更新,更新后需执行sync同步操作并重启生效。文章特别强调操作过程中断电风险,并扩展说明了Uboot的类似更新方法。该方法避免了现场设备拆卸的麻烦,为嵌入式系统维护提供了实用解决方案。

荻夜的博客 1067

Python 爬虫实战:科研数据库学术论文数据抓取

在科研工作中,学术论文是获取前沿知识和研究方法的重要资源。然而,手动从科研数据库中查找和整理论文信息往往耗时费力。幸运的是,Python 爬虫技术可以自动化这一过程,帮助我们高效地抓取和管理学术论文数据。本文将详细介绍如何使用 Python 爬虫技术抓取科研数据库中的学术论文数据,并进行全字段提取和文献管理,助力科研工作。

u014481728的博客 958

查找练习 hash——出现过的数字(哈希查找)

查找练习 hash——出现过的数字 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 有一个数据字典,里面存有n个数字(n   输入  输入数据只有一组! 第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。 接着n行代表字典中的n个数字。

flyljg的专栏 951

在 VS Code 里配置 SAP Joule for Developers 的 ABAP AI side-by-side 能力

摘要: 随着ABAP开发工具链的演进,VS Code逐渐融入ABAP开发流程,SAP Joule for Developers的ABAP AI能力通过side-by-side模式(基于BTP中央服务)为多系统开发提供统一AI支持。该模式避免了各ABAP后端独立升级AI能力的碎片化问题,由管理员配置BTP订阅URL后,开发者可在ADT或VS Code中全局调用。实际落地需注意角色分工(管理员配置服务,开发者填写URL)、AI units资源规划及配置细节(如区分全局与项目级设置)。建议将Joule URL纳入

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 129

【2123】查找练习 hash——出现过的数字(哈希表)

 查找练习 hash——出现过的数字 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 有一个数据字典,里面存有n个数字(n   输入  输入数据只有一组! 第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。 接着n行代表字典中的n个数字。

jiangyongy的专栏 1009

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

查找练习 hash——出现过的数字(SDUT 2123)

 查找练习 hash——出现过的数字 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 有一个数据字典,里面存有n个数字(n   输入  输入数据只有一组! 第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。 接着n行代表字典中的n个数字。 最后m表

Rocky0429 1636

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[SDUT](2123)查找练习 hash——出现过的数字 ---哈希查找(查找)

查找练习 hash——出现过的数字 Time Limit:1000MSMemory Limit:65536KB SubmitStatisticDiscuss Problem Description 有一个数据字典,里面存有n个数字(n<=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这...

138

查找练习 hash——出现过的数字 SDUT

查找练习 hash——出现过的数字 SDUT Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 有一个数据字典,里面存有n个数字(n&lt;=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量的问题,小明找...

weixin_43892738的博客 176

day10——查找练习 hash——出现过的数字(掌握方法)

查找练习 hash——出现过的数字 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 有一个数据字典,里面存有n个数字(n&lt;=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量...

芒果summer小仙女 423

查找练习 hash——出现过的数字 oj sdut

查找练习 hash——出现过的数字 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 有一个数据字典,里面存有n个数字(n 输入 输入数据只有一组! 第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。 接着n行代表字典中的n个数字。 最后m表示要查询的数字。

Welcome ! This is Guanpx's blog. 721
上一篇: 数据结构实验之查找四:二分查找
下一篇: 数据结构实验:哈希表
mrxs
博客等级 码龄10年 102粉丝 381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值