POJ Black Box 1442(优先队列)

大(小)顶堆练习:POJ 1442 NULL 博文链接:https://128kj.iteye.com/blog/1753387 立即下载



                                                                                              Black Box
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 10302 Accepted: 4237

Description

Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i equals 0. This Black Box processes a sequence of commands (transactions). There are two types of transactions:

ADD (x): put element x into Black Box;
GET: increase i by 1 and give an i-minimum out of all integers containing in the Black Box. Keep in mind that i-minimum is a number located at i-th place after Black Box elements sorting by non-descending(下降).

Let us examine a possible sequence of 11 transactions:

Example 1
N Transaction i Black Box contents after transaction Answer 
      (elements are arranged by non-descending)   
1 ADD(3)      0 3   
2 GET         1 3                                    3 
3 ADD(1)      1 1, 3   
4 GET         2 1, 3                                 3 
5 ADD(-4)     2 -4, 1, 3   
6 ADD(2)      2 -4, 1, 2, 3   
7 ADD(8)      2 -4, 1, 2, 3, 8   
8 ADD(-1000)  2 -1000, -4, 1, 2, 3, 8   
9 GET         3 -1000, -4, 1, 2, 3, 8                1 
10 GET        4 -1000, -4, 1, 2, 3, 8                2 
11 ADD(2)     4 -1000, -4, 1, 2, 2, 3, 8   

It is required to work out an efficient algorithm which treats a given sequence of transactions. The maximum number of ADD and GET transactions: 30000 of each type.


Let us describe the sequence of transactions by two integer arrays:


1. A(1), A(2), ..., A(M): a sequence of elements which are being included into Black Box. A values are integers not exceeding 2 000 000 000 by their absolute value, M <= 30000. For the Example we have A=(3, 1, -4, 2, 8, -1000, 2).

2. u(1), u(2), ..., u(N): a sequence setting a number of elements which are being included into Black Box at the moment of first, second, ... and N-transaction GET. For the Example we have u=(1, 2, 6, 6).

The Black Box algorithm supposes that natural number sequence u(1), u(2), ..., u(N) is sorted in non-descending order, N <= M and for each p (1 <= p <= N) aninequality(不平等) p <= u(p) <= M is valid. It follows from the fact that for the p-element of our u sequence we perform a GET transaction giving p-minimum number from our A(1), A(2), ..., A(u(p)) sequence.


Input

Input contains (in given order): M, N, A(1), A(2), ..., A(M), u(1), u(2), ..., u(N). All numbers are divided by spaces and (or) carriage return characters.

Output

Write to the output Black Box answers sequence for a given sequence of transactions, one number each line.

Sample Input

7 4
3 1 -4 2 8 -1000 2
1 2 6 6

Sample Output

3
3
1
2


网上大神说的http://blog.youkuaiyun.com/lyhvoyage/article/details/18360655

题意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。


分析:因为输出时是按照先输出最小的,再输出第二小这样的方式输出的,相当于依次输出一个有序序列中的值。但因为这个序列不是固定不变的,而是不断的在更新,所以用数组是无法实现的。我们可以用优先队列来做。

定义两个优先队列,一个用来存储前k小的数,大数在前,小数在后;另一个优先队列第k+1小到最大的数,小数在前,大数在后。每次拿到一个数,先判断第一个优先队列中的数满不满k个,如果不满k个,则直接把这个数压入到第一个队列;如果满k个,判断这个数和第一个优先队列中的第一个数的大小:如果比第一个数大,就压入第二个优先队列;如果比第一个数小,就把第一个优先队列的队首元素弹出压入第二个队列,把这个新数压入第一个优先队列。

输出时,如果第一个优先队列里的元素个数小于k,则先把第二个优先队列里的队首元素弹出压入第一个优先队列,然后输出第一个优先队列的队首元素;如果满k个,则直接输出第一个优先队列的队首元素。



我也是按照他说的写


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <algorithm>
using namespace std;
int main()
{
    int a[30010],b[30010];
    int n,m,i,j,k,x;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&b[i]);
    }
    priority_queue<int,vector<int>,greater<int> >q1;//k+1...da
    priority_queue<int,vector<int>,less<int> >q2;//da
    i=0;j=0;k=1;
    while(j<m)
    {
        if(i==b[j])
        {
            j++;
            if(q2.size()<k)
            {
                x=q1.top();
                q1.pop();
                q2.push(x);
            }
            x=q2.top();
            printf("%d\n",x);
            k++;
        }
        else
        {
            if(q2.size()<k)
            {
                q1.push(a[i]);
                x=q1.top();
                q1.pop();
                q2.push(x);
            }
            else if(q2.top()>a[i])
            {
                x=q2.top();
                q2.pop();
                q1.push(x);
                q2.push(a[i]);
            }
            else
            {
                q1.push(a[i]);
            }
            i++;
        }
    }
    return 0;
}




















【关于四足机器人那些事】足端轨迹规划-八次多项式轨迹 系列文章目录 文章目录系列文章目录前言一、多项式曲线二、八次多项式曲线总结 前言 在四足机器人的研究中,有一个很关键的问题,就是如何减少足端在触地瞬间的冲击,避免把机器人把自己给蹬倒了?这时候就需要一个合理的足端轨迹规划。本篇将会介绍几种足端轨迹。 本文将对四足机器人的足端轨迹进行规划。将数学中的复合摆线和多项式曲线引入到足端轨迹的规划中,根据零冲击原则[2],规划出 3 条满足要求的足端轨迹,包括: 复合摆线轨迹 八次多项式轨迹 分段五次多项式轨迹 本篇先介绍 - 八次多项式轨迹 一、多项式曲 阅读详情

相关推荐

【实战指南】Jaspersoft Studio + JasperReports:从零构建企业级PDF报表

本文详细介绍了如何使用Jaspersoft Studio和JasperReports从零构建企业级PDF报表。通过可视化设计、数据连接、模板设计到最终输出的全链路支持,这套组合方案显著降低了报表开发的维护成本。文章还提供了开发环境搭建、中文乱码解决方案、Java集成代码及性能优化技巧,适合需要高效生成复杂PDF报表的开发者。

weixin_42666036的博客 247

优先队列——大小堆—— priority_queue

在我们学习二叉树时接触过大小堆;大堆:在一颗完全二叉树中,大数在堆顶,小数在下方;小堆:乃相反,在完全二叉树中,最小的数在堆顶,大数在下方;提示:以下是本篇文章正文内容,下面案例可供参考会用priority_queue的各个函数和理解堆掌握仿函数的调用和函数的重载。

2301_80687320的博客 1518

SAP FICO 资产会计AA后台配置 (上)

输入折旧表“CZ11”如有外币计价的资产,则需指定外币计价的资产折旧范围,以及规则。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。新增资产类型:Z101 固定资产-房屋及建筑物新增资产类型:Z301 固定资产-房屋及建筑物。

ghgxm520的博客 1762

POJ 1442 Black Box (优先队列)

Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6246   Accepted: 2532 Description Our Black Box represents a primitive database. It can save an int

LYHVOYAGE的专栏 4559

一文搞懂【Linux 搭建 Dread Hunger 服务器】附本体及Docker部署集群方案

看直播发现了五花八门的开服器和版本,一时兴起按官方文档进行了搭建尝试,所以我的版本基于官方Stream2024.01.10更新的版本,也就是停服时的玩法,应该可以根据mod和补丁魔改成更那些开服器一样的版本,本文不做谈论,注重服务器搭建,毕竟8个人不可能在一个局域网里乱象:首先,我看了大量教程视频,一类是开服器的推广,另一类自建的基本采用Windows搭建,我觉得最离谱的是大部分教程都会教你买一台远程Windows虚拟机???

LHmine的博客 3987

人大金仓V8R3企业版License更新全攻略:从查看到重启一步到位

本文详细解析了人大金仓V8R3企业版License更新的完整运维流程,涵盖从诊断当前授权状态、获取与验证新文件、精准定位旧文件路径,到安全替换文件及服务重启验证的全过程。重点针对更新流程中常见的版本匹配、文件定位、权限与服务重启等关键环节提供了实战解决方案和避坑指南,帮助运维人员高效、平稳地完成授权续期。

redis7keeper的博客 900

POJ——1442(优先队列)

题目来源:http://poj.org/problem?id=1442 参考链接:https://blog.csdn.net/LYHVOYAGE/article/details/18360655 题目大意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。 解题分析:创建两个优先队列,...

Asher 943

深入浅出ASAP2标准:手把手教你编写和解析A2L文件(含Python示例代码)

本文深入解析ASAP2标准下的A2L文件,涵盖基础概念、文件结构及Python实现代码,帮助开发者掌握汽车ECU标定和测量中的关键数据管理技术。通过详细示例,展示如何编写和解析A2L文件,提升电控数据管理效率。

happy2的博客 1100

Black Box - POJ 1442 - Treap

链接:  http://poj.org/problem?id=1442题目:DescriptionOur Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i

LucienShui 686

瑞芯微RK3506开发板Ethercat主站性能优化实战:从内核配置到微秒级延迟控制

本文详细介绍了在瑞芯微RK3506开发板上实现EtherCAT主站微秒级延迟控制的实战优化方案。核心在于部署Preempt-RT实时内核,并进行深度系统调优,包括CPU隔离、中断亲和性设置、内存锁定及电源管理调整。通过绕过Linux网络栈的专用驱动加载与配置,最终实现了稳定的高性能实时控制,满足工业自动化需求。

tcp8optimizer的博客 315

基于Simulink的压缩空气储能(Compressed Air Energy Storage, CAES)

压缩空气储能(CAES)是一种将电能转化为压缩空气存储在高压容器中,然后在需要时释放空气驱动涡轮机发电的技术。它具有大规模、长寿命和环境友好的特点,在电力系统中用于削峰填谷、频率调节和备用电源等应用。本项目将详细介绍如何在MATLAB/Simulink中搭建一个完整的基于压缩空气储能的系统,并提供具体的代码实现和设计步骤。如果你需要实现更复杂的控制逻辑,可以使用MATLAB Function模块。以下是一个简单的例子,展示了如何在该模块中实现一个条件逻辑:Matlab深色版本Kp = 1;

MHD0815的博客 1274

【POJ 1442】Black Box 题解(优先队列+对顶堆)

我们的黑盒代表了一个原始数据库。它可以保存一个整数数组,并且有一个特殊的i变量。在初始时刻,黑盒为空,i等于0。这个黑盒处理一系列命令(事务)。有两种类型的交易:ADD(x):将元素x放入黑盒中;GET:将i增加1,并在黑盒中包含的所有整数中给出i最小值。请记住,i-minimum是一个位于黑盒元素按非降序排序后第i位的数字。让我们检查11个交易的可能序列:示例1N交易i交易应答后的黑匣子内容(元素按非降序排列)1添加(3)0 32得到1 3 33加(1)1 1,3。

HEX9CF的技术博客 933

MATLAB和S7-1200PLC水箱液位高度PID控制联合仿真(KEPserverOPC通信应用)

SMART PLC 向导PID的详细介绍请查看下面文章链接:S7-200 SMART PLC PID向导详细介绍(如何实现P、PD、PID控制器)-优快云博客文章浏览阅读1k次。这篇博客主要介绍SMART PLC PID向导的使用,PID控制相关的其它内容请查看专栏系列文章,常用链接如下:SMART PLC PID负压控制(过程量为负数)_负压控制pid控制程序_RXXW_Dor的博客-优快云博客1、如何实现PID反作用调节?S7-1200PLC和KEPserver OPC通信-优快云博客。

RXXW_Dor的博客 1781

POJ 1442 Black Box(优先队列)

Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8710   Accepted: 3576 Description Our Black Box represents a primitive database. It can save an int

叶孤心的专栏 816

ssm框架搭建

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Poj 1442 Black Box(优先队列水题)

Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8070   Accepted: 3309 Description Our Black Box represents a primitive database. It can save an i

u013082590的专栏 1089

深度学习工具包 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")

POJ 1442 Black Box 优先队列

POJ 1442 可以当做是优先队列的模板 /* poj 1442 题意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,    第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。 优先队列的使用: 本题思路是建立一个小顶堆p和一个大顶堆q, q保存前k个小的数,且保证p的值都比q的大, 最后输出q的顶 ...

ailincheng0815的博客 277

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【POJ1442】 - - Black Box(优先队列)

题意:按要求输出所给序列中第k小的数 解题思路:维护两个优先队列,一个最小堆,一个最大堆,最终想要的效果是每次输入就是弹出最小堆中的最小值就是所要的值,也就是说比最小值还要小的值,被想办法放到了别处(不能直接去掉,因为后面可能还会用到)。逆向思路是,每次输出完的那个数,把它放进最大堆中,在求第k个最小值时,前k个数都压进最小优先队列,如果最大优先队列不为空,就把最大值拿出来和最小优先队列的最小值

MingShen 708

[优先队列]Black Box POJ1442

学长写了一个SQL,这个SQL有一个特殊变量i,初值为0而且只有两种操作: ADD (x): 把x存入SQL GET: i=i+1,然后输出第i小的数 现在给你一个长为M的ADD操作序列A,N个时间点序列B,要求在每个B[i]时执行一次GET操作,求输出结果序列 Input 输入第一行有两个数字M, N 接下来是M个数字A(1), A(2), ..., A(M) 再下来是N个数字B(1), B(2), ..., B(N). 这N个数字已经从小到大排序过 本题数据范围均在int内 ADD和GET操作分别最

Cloth的博客 623

POJ 1442 Black Box(优先队列)

题目地址:POJ 1442 这题是用了两个优先队列,其中一个是较大优先,另一个是较小优先。让较大优先的队列保持k个。每次输出较大优先队列的队头。 每次取出一个数之后,都要先进行判断,如果这个数比较大优先的队列的队头要小,就让它加入这个队列,队列头移到较小优先的队列中。然后当较大优先的数不足k个的时候,就让较小优先的队列的队头移到较大优先的队头中。 代码如下; #include #incl

scf0920 1196

优先队列(堆)poj1442Black Box

给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。

2301_79646104的博客 1016

【POJ 1442 --- Black Box】大根堆和小根堆,优先队列

【POJ 1442 --- Black Box】大根堆和小根堆,优先队列 Description Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and ...

来日浅谈的博客 545

poj1442 Black Box 栈和优先队列

题意:有n个数,按顺序加入,求加入前Gi个数时第i个最小的数是多少 思路:这里需要用到STL里的优先队列priority_queue,建一个大堆和一个小堆,若想在一个无序的序列里找第n个小的数,可以先把一个序列的n-1个数放入大堆(即假设这n-1个数是该序列里最小的),然后向小堆里push数,若小堆头元素<大堆头元素(即最小的元素比最大的元素大,说明大堆里的数还不是最小的)...

aidibi1469的博客 161

POJ 1442 Black Box(优先队列+对顶堆)

传送门 题目大意 有一些ADD和GET操作。n次ADD操作,每次往序列中加入一个数,由ADD操作可知序列长度为1-n时序列的组成。GET操作输入一个序列长度,输出当前长度序列第i大的元素的值。i初始为0,每次GET操作i先加1。给出的GET操作输入非降。 思路 对顶堆 大根堆维护小于当前需询问的节点的值 小根堆维护大于当前需询问的节点的值 那么大根堆的size等于当前询问的节点时,大根堆的堆顶就是答案。 代码 ll u[maxn],a[maxn]; //小根堆维护大于等于当前节点的数 //大根堆维护小于当前

幼儿园大哥~ 284

POJ-1442-Black Box-优先队列

题意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。 分析:因为输出时是按照先输出最小的,再输出第二小这样的方式输出的,相当于依次输出一个有序序列中的值。但因为这个序列不是固定不变的,而是不断的在更新,所以用数组是无法实现的。我们可以用优先队列来做。 定义两个优先队列,一个用

命运在指间 652

poj1442Black Box(优先队列)

http://poj.org/problem?id=1442 题意很难懂 题挺巧妙的 建立两个优先队列 一个从小到大 另一个从大到小 随时更新两队中的值 使其为1~i 和i+1~m View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #in...

weixin_30484247的博客 94

poj 1442 Black Box(优先队列&Treap)

题目链接:http://poj.org/problem?id=1442 思路分析: <1>维护一个最小堆与最大堆,最大堆中存储最小的K个数,其余存储在最小堆中; <2>使用Treap构造名次树,查询第K大数即可; 代码如下(堆的用法): #include<iostream> #include<queue> using...

aqjh9999的博客 167
上一篇: POJ Colored Sticks 2513(字典树+并查集+欧拉回路)
下一篇: POJ Gold Balanced Lineup 3274 哈希
K_y
K_y
博客等级 码龄10年 4粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值