当前位置:网站首页>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;
}
边栏推荐
- go语言学习笔记-分析第一个程序
- About the use of Vray 5.2 (self research notes)
- 数据类型 ntext 和 varchar 在not equal to 运算符中不兼容 -九五小庞
- 2022 chemical automation control instrument examination questions and online simulation examination
- Basic part - basic project analysis
- 龙蜥社区第九次运营委员会会议顺利召开
- Nuxt//
- Cron表达式(七子表达式)
- TSQL – identity column, guid, sequence
- Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
猜你喜欢
Basic testing process of CSDN Software Testing Introduction
[advertising system] parameter server distributed training
About the use of Vray 5.2 (self research notes)
7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
[JS learning notes 54] BFC mode
修复动漫1K变8K
华为设备配置信道切换业务不中断
How to introduce devsecops into enterprises?
Codeforces Round #804 (Div. 2)
随机推荐
Paradigm in database: first paradigm, second paradigm, third paradigm
shell脚本文件遍历 str转数组 字符串拼接
[first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
[TCP] TCP connection status JSON output on the server
Characteristics and electrical parameters of DDR4
spark调优(一):从hql转向代码
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
C # to obtain the filtered or sorted data of the GridView table in devaexpress
websocket
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
Web Security
无密码身份验证如何保障用户隐私安全?
龙蜥社区第九次运营委员会会议顺利召开
九、磁盘管理
四部门:从即日起至10月底开展燃气安全“百日行动”
Function///
2022 t elevator repair operation certificate examination questions and answers
Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
OneForAll安装使用
2022 Pengcheng cup Web