当前位置:网站首页>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;
}
边栏推荐
- Web Security
- Applet framework taro
- Stop saying that microservices can solve all problems!
- 【Oracle】使用DataGrip连接Oracle数据库
- 购买小间距LED显示屏的三个建议
- 居家办公那些事|社区征文
- How can edge computing be combined with the Internet of things?
- Advanced scaffold development
- SLAM 01. Modeling of human recognition Environment & path
- 我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
猜你喜欢
![[advertising system] parameter server distributed training](/img/8b/558c2fefbd16b580546003f3afeaf5.png)
[advertising system] parameter server distributed training

龙蜥社区第九次运营委员会会议顺利召开

Do you really understand the things about "prototype"? [part I]

R3live series learning (IV) r2live source code reading (2)

Modulenotfounderror: no module named 'scratch' ultimate solution

OneForAll安装使用
![[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output](/img/96/b8585205b3faf503686c5bbdcecc53.png)
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output

【爬虫】wasm遇到的bug

不要再说微服务可以解决一切问题了!

Stop saying that microservices can solve all problems!
随机推荐
In the last process before the use of the risk control model, 80% of children's shoes are trampled here
百问百答第45期:应用性能探针监测原理-node JS 探针
Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
COMSOL--三维随便画--扫掠
R3Live系列学习(四)R2Live源码阅读(2)
Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!
四部门:从即日起至10月底开展燃气安全“百日行动”
居家办公那些事|社区征文
iframe
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Spark Tuning (I): from HQL to code
龙蜥社区第九次运营委员会会议顺利召开
matlab cov函数详解
技术分享 | 常见接口协议解析
Bidirectional RNN and stacked bidirectional RNN
Detailed explanation of MATLAB cov function
修复动漫1K变8K
[there may be no default font]warning: imagettfbbox() [function.imagettfbbox]: invalid font filename
【广告系统】Parameter Server分布式训练