当前位置:网站首页>Zcmu--1390: queue problem (1)
Zcmu--1390: queue problem (1)
2022-07-05 11:17:00 【Little why】
Description
Given a queue q, Each element in the queue has two attributes name and pri. For queues 3 The operations in are : 1 name pri Represents adding... To the queue (name,pri) This element . 2 Represents in the output queue pri The highest element name And remove the element from the queue . 3 Represents in the output queue pri Of the lowest element name And remove the element from the queue . Suppose the queue is initially empty , And all elements name The values are different ,pri Values also vary . Given a number of operations , about 2 and 3 The operation outputs the name.
Input
Each line of input represents an operation , If the input is 0 End .(1<=name,pri<=10^6)
Output
For each 2 and 3 operation , Output the corresponding value . If there are no elements in the queue, output 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
analysis : Because it will be based on pri Maximum value to output name , This one uses set It's very convenient , because set It will automatically sort and store , We can quickly find the most value in the queue , As for the output corresponding name, one-on-one , So we use map It's very convenient !
#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){ // Instructions 1
scanf("%d%d",&a,&b);
st.insert(b); // Deposit in set in
mp[b]=a; // Corresponding settings name
}else if(z==2){ // Instructions 2
if(st.size()){ // If it's not empty
printf("%d\n",mp[*st.rbegin()]);//*st.rbegin() Represents the last element value
st.erase(--st.end()); // Delete the last element
}else printf("0\n"); // Null output 0
}else{ // Instructions 3
if(st.size()){ // ditto
printf("%d\n",mp[*st.begin()]);
st.erase(st.begin());
}else printf("0\n");
}
}
return 0;
}
边栏推荐
- Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!
- Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
- DOM//
- deepfake教程
- Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
- 技术分享 | 常见接口协议解析
- Bracket matching problem (STL)
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- Data type
- uboot的启动流程:
猜你喜欢
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
九、磁盘管理
关于vray5.2怎么关闭日志窗口
Do you really understand the things about "prototype"? [part I]
一次edu证书站的挖掘
数据库三大范式
In the last process before the use of the risk control model, 80% of children's shoes are trampled here
如何让全彩LED显示屏更加节能环保
Basics - rest style development
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
随机推荐
How to introduce devsecops into enterprises?
32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
Redis如何实现多可用区?
【爬虫】wasm遇到的bug
How to make full-color LED display more energy-saving and environmental protection
Data type
关于vray5.2怎么关闭日志窗口
Characteristics and electrical parameters of DDR4
关于 “原型” 的那些事你真的理解了吗?【上篇】
[JS learning notes 54] BFC mode
Web Components
Explanation of message passing in DGL
Data types ntext and varchar are incompatible in the not equal to operator - 95 small pang
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
When using gbase 8C database, an error is reported: 80000502, cluster:%s is busy. What's going on?
MFC pet store information management system
Bidirectional RNN and stacked bidirectional RNN
FFmpeg调用avformat_open_input时返回错误 -22(Invalid argument)
[office] eight usages of if function in Excel
About the use of Vray 5.2 (self research notes)