当前位置:网站首页>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;
}
边栏推荐
- 基础篇——基础项目解析
- Paradigm in database: first paradigm, second paradigm, third paradigm
- Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
- Advanced scaffold development
- 【Office】Excel中IF函数的8种用法
- Stop saying that microservices can solve all problems!
- 【爬虫】wasm遇到的bug
- uniapp
- 磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
- Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
猜你喜欢
32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
九、磁盘管理
How to make full-color LED display more energy-saving and environmental protection
Characteristics and electrical parameters of DDR4
无密码身份验证如何保障用户隐私安全?
基础篇——REST风格开发
comsol--三维图形随便画----回转
LSTM applied to MNIST dataset classification (compared with CNN)
关于vray 5.2的使用(自研笔记)
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
随机推荐
How to make full-color LED display more energy-saving and environmental protection
Honing · fusion | know that the official website of Chuangyu mobile terminal is newly launched, and start the journey of digital security!
Paradigm in database: first paradigm, second paradigm, third paradigm
管理多个Instagram帐户防关联小技巧大分享
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
pytorch训练进程被中断了
Codeforces Round #804 (Div. 2)
-26374 and -26377 errors during coneroller execution
磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
Intelligent metal detector based on openharmony
Four departments: from now on to the end of October, carry out the "100 day action" on gas safety
About the use of Vray 5.2 (self research notes)
TSQL – identity column, guid, sequence
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
Scaffold development foundation
BOM//
Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
[JS learning notes 54] BFC mode
COMSOL--三维图形的建立
九、磁盘管理