当前位置:网站首页>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;
}
边栏推荐
- 【Oracle】使用DataGrip连接Oracle数据库
- DDoS attack principle, the phenomenon of being attacked by DDoS
- IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
- DDRx寻址原理
- [TCP] TCP connection status JSON output on the server
- msfconsole命令大全,以及使用说明
- Intelligent metal detector based on openharmony
- Three paradigms of database
- SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
- [JS learning notes 54] BFC mode
猜你喜欢

NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?

A mining of edu certificate station

华为设备配置信道切换业务不中断

【DNS】“Can‘t resolve host“ as non-root user, but works fine as root

紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成

Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?

DDR4的特性与电气参数
![[JS learning notes 54] BFC mode](/img/47/a07084ef6064589d2eeb6f091753e0.png)
[JS learning notes 54] BFC mode

修复动漫1K变8K

How to introduce devsecops into enterprises?
随机推荐
关于vray 5.2的使用(自研笔记)
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
About the use of Vray 5.2 (self research notes)
Web Components
Repair animation 1K to 8K
I used Kaitian platform to build an urban epidemic prevention policy inquiry system [Kaitian apaas battle]
百问百答第45期:应用性能探针监测原理-node JS 探针
【全网首发】(大表小技巧)有时候 2 小时的 SQL 操作,可能只要 1 分钟
Buried point 111
如何通俗理解超级浏览器?可以用于哪些场景?有哪些品牌?
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
如何让全彩LED显示屏更加节能环保
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
DDR4硬件原理图设计详解
【广告系统】增量训练 & 特征准入/特征淘汰
购买小间距LED显示屏的三个建议
[advertising system] parameter server distributed training
Detailed explanation of DDR4 hardware schematic design
Variables///
Three paradigms of database