当前位置:网站首页>ZCMU--1390: 队列问题(1)
ZCMU--1390: 队列问题(1)
2022-07-05 11:13:00 【小小小Why】
Description
给定一个队列q,队列中的每个元素都有两种属性name和pri。对于队列有3中操作分别为: 1 name pri 代表向队列中添加(name,pri)这个元素。 2 代表输出队列中pri最高的元素的name并将该元素移除队列。 3 代表输出队列中pri最低的元素的name并将该元素移除队列。 假设队列初始为空,且所有元素的name值各不相同,pri值也各不相同。给定若干操作,对于2和3操作输出相应元素的name。
Input
每行输入分别代表一种操作,若输入为0则结束。(1<=name,pri<=10^6)
Output
对于每个2和3操作,输出对应的值。若队列中没有元素则输出0。
Sample Input
2
1 20 14
1 30 3
2
1 10 99
3
2
2
0
Sample Output
0
20
30
10
0
解析:因为会根据 pri 最值来输出 name ,这个用set就很方便,因为set会自动排序存贮,我们就可以迅速的查找队列中的最值,至于输出对应的name,一对一,那么我们用map就十分方便莫!
#include <stdio.h>
#include <map>
#include <set>
using namespace std;
int main()
{
map<int,int>mp;
set<int>st;
int z,a,b;
while(~scanf("%d",&z),z!=0){
if(z==1){ //指令1
scanf("%d%d",&a,&b);
st.insert(b); //存入set中
mp[b]=a; //对应设置name
}else if(z==2){ //指令2
if(st.size()){ //如果不为空
printf("%d\n",mp[*st.rbegin()]);//*st.rbegin()表示最后一个元素值
st.erase(--st.end()); //删除最后一个元素
}else printf("0\n"); //为空输出0
}else{ //指令3
if(st.size()){ //同上
printf("%d\n",mp[*st.begin()]);
st.erase(st.begin());
}else printf("0\n");
}
}
return 0;
}
边栏推荐
- Detailed explanation of DDR4 hardware schematic design
- COMSOL--建立几何模型---二维图形的建立
- Detailed explanation of MATLAB cov function
- Honing · fusion | know that the official website of Chuangyu mobile terminal is newly launched, and start the journey of digital security!
- Function///
- Four departments: from now on to the end of October, carry out the "100 day action" on gas safety
- 技术分享 | 常见接口协议解析
- Intelligent metal detector based on openharmony
- 关于vray 5.2的使用(自研笔记)(二)
- Dspic33ep clock initialization program
猜你喜欢
Three paradigms of database
Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
COMSOL--建立几何模型---二维图形的建立
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
pytorch训练进程被中断了
关于vray 5.2的使用(自研笔记)
Characteristics and electrical parameters of DDR4
分类TAB商品流多目标排序模型的演进
R3live series learning (IV) r2live source code reading (2)
随机推荐
Variables///
matlab cov函数详解
Solve the problem of slow access to foreign public static resources
力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
[JS learning notes 54] BFC mode
Oneforall installation and use
【Office】Excel中IF函数的8种用法
Nuxt//
Go language learning notes - analyze the first program
7.2每日学习4
How can edge computing be combined with the Internet of things?
About the use of Vray 5.2 (self research notes)
9、 Disk management
Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!
DDR4的特性与电气参数
[SWT component] content scrolledcomposite
紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成
About the use of Vray 5.2 (self research notes)
如何让全彩LED显示屏更加节能环保
FFmpeg调用avformat_open_input时返回错误 -22(Invalid argument)