Update 18.2.27----想当年我还用着C.....

看到题解里一堆用C++ STL库中的优先队列,身为C语言选手心里不是滋味

故手打一个优先队列献给坚守在C语言的选手

#include <stdio.h>
#define maxn 1000050
int que1[maxn];
int head=1,tail=0;
int n;
int get()
{
short int neg=0;int a;char c;
while((c=getchar())>'9'||c<'0') neg=c=='-';
a=c-48;
while((c=getchar())>='0'&&c<='9')a=(a<<3)+(a<<1)+c-48;
return neg?-a:a;
}
int main()
{
int i,j,x,y;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
x=get();
if(x==1)
{
y=get();
j=tail;
while(head<=j&&y<que1[j]){que1[j+1]=que1[j];j--;}//实际操作中有时可以直接tail--
tail++;
que1[++j]=y;
}
else if(x==2) printf("%d\n",que1[head]);
else if(x==3) head++;
}
return 0;
}
祝大家 NOIP 2017 rp++

题解 P3378 【【模板】堆】的更多相关文章

  1. 堆/题解 P3378 【【模板】堆】

    概念: 堆就是一颗二叉树,满足父亲节点总是比儿子节点大(小).因此,堆也分为大根堆和小根堆,大根堆就是父亲节点比儿子节点大,小根堆正好相反.注意加粗的地方,是每一个节点哦!!!!! 还是直接看例题吧, ...

  2. 最短路模板|堆优化Dijkstra,SPFA,floyd

    Ⅰ:Dijkstra单源点最短路 1.1Dijkstra const int MAX_N = 10000; const int MAX_M = 100000; const int inf = 0x3f ...

  3. luogu P1552 [APIO2012]派遣 题解--可并堆/贪心

    题目链接: https://www.luogu.org/problemnew/show/P1552 分析: 一开始愣是没看懂题,后面发现就是你要找一个树上点集使得各点权值之和小于\(M\),并且找一个 ...

  4. 字符串 kmp算法 codeforce 625B 题解(模板)

    题解:kmp算法 代码: #include <iostream>#include <algorithm>#include <cstring>#include < ...

  5. 【NOI2010】超级钢琴 题解(贪心+堆+ST表)

    题目链接 题目大意:求序列内长度在$[L,R]$范围内前$k$大子序列之和. ---------------------- 考略每个左端点$i$,合法的区间右端点在$[i+L,i+R]$内. 不妨暴力 ...

  6. 【JZOJ4726】种花 题解(贪心+堆)

    题目大意:在一个长度为$n$的环型序列中取出$m$个数使这$m$个数的和最大,且要求这$m$个数互不相邻. ---------------------- 考虑维护$nxt$和$lst$,即一个数的前驱 ...

  7. CCF-CSP题解 201509-3 模板生成系统

    简单的替换一下字符串. 注意数组开大点. #include<bits/stdc++.h> const int maxm = 100; const int maxn = 100; using ...

  8. 模板—堆优化dijkstra

    ];]; void dijkstra(int s) { memset(dis,0x7f,sizeof(dis));ma(v); priority_queue<pair<int,int> ...

  9. 【luogu P3378 堆】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3378 是堆的模板...我懒,STL da fa is good #include <iostream& ...

随机推荐

  1. Ionic 的安装运行

    1.学习前准备工作 1.必须得安装 nodejs (建议安装最新的稳定版本) 2.必须有 Angular 基础:https://www.loaderman.com/goods-1047.html 2. ...

  2. Qt KDChart编译

    最近开发中需要用到甘特图,感觉KDChart这个插件不错,在这里记录一下编译过程(其实很好编译,而且一次性就过了) 下载,kdchart-2.6.1-source,解压 打开src目录,用Qt Cre ...

  3. Transaction check error:

    Transaction check error:  file /etc/my.cnf from install of MariaDB-common-10.3.16-1.el7.centos.x86_6 ...

  4. Python - Django - 显示作者列表

    在 views.py 中添加展示作者列表的函数 from django.shortcuts import render, redirect, HttpResponse from app01 impor ...

  5. LeetCode_167. Two Sum II - Input array is sorted

    167. Two Sum II - Input array is sorted Easy Given an array of integers that is already sorted in as ...

  6. LeetCode_70. Climbing Stairs

    70. Climbing Stairs Easy You are climbing a stair case. It takes n steps to reach to the top. Each t ...

  7. 解决 OpenCV with CUDA 编译提示缺少 nvcuvid.h 的问题

    系统环境: 操作系统:Ubuntu 18.04.01 显卡型号:GeForce GTX 1060 6G CMake 版本:3.10.2 GCC 版本:7.4.0 GNU Make 版本:4.1 CUD ...

  8. eNSP——OSPF的基础配置

    原理: 模拟实验: 拓扑图: 实验编址: 1.基本配置 根据实验编址和拓扑图进行基本配置,并测试连通性. 2.部署OSPF网络 首先使用ospf命令创建并运行OSPF,1代表进程号 接着使用area命 ...

  9. nginx check健康检查

    nginx利用第三方模块nginx_upstream_check_module来检查后端服务器的健康情况 大家都知道,前段nginx做反代,如果后端服务器宕掉的话,nginx是不能把这台realser ...

  10. The Select mechanism in linux for block mechanism

    Today, some one mention theknowledge of Select Mechanism. It's better to konw something about it ! O ...