当前位置:网站首页>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;
}
边栏推荐
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- 2022 mobile crane driver examination question bank and simulation examination
- LSTM applied to MNIST dataset classification (compared with CNN)
- How to introduce devsecops into enterprises?
- 管理多个Instagram帐户防关联小技巧大分享
- 【爬虫】wasm遇到的bug
- Three paradigms of database
- pytorch训练进程被中断了
- Honing · fusion | know that the official website of Chuangyu mobile terminal is newly launched, and start the journey of digital security!
- 解决访问国外公共静态资源速度慢的问题
猜你喜欢
In the last process before the use of the risk control model, 80% of children's shoes are trampled here
[advertising system] parameter server distributed training
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
How to close the log window in vray5.2
LSTM applied to MNIST dataset classification (compared with CNN)
Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
2022 t elevator repair operation certificate examination questions and answers
九、磁盘管理
go语言学习笔记-初识Go语言
Detailed explanation of DDR4 hardware schematic design
随机推荐
websocket
DDRx寻址原理
如何将 DevSecOps 引入企业?
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
DDR4硬件原理图设计详解
uboot的启动流程:
基础篇——基础项目解析
Bracket matching problem (STL)
2022 mobile crane driver examination question bank and simulation examination
When using gbase 8C database, an error is reported: 80000502, cluster:%s is busy. What's going on?
Variables///
Web Components
【Office】Excel中IF函数的8种用法
Stop saying that microservices can solve all problems!
shell脚本文件遍历 str转数组 字符串拼接
关于vray 5.2的使用(自研笔记)
管理多个Instagram帐户防关联小技巧大分享
Dspic33ep clock initialization program
About the use of Vray 5.2 (self research notes)
【广告系统】Parameter Server分布式训练