题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少。

析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下队列是不是空的,然后再考虑getMin,这个是不是对应的值,如果队列中首元素比它大,那么就加上一个,

如果相等直接取出,如果小于就不断取队列中最小元素。

代码如下:

#include <bits/stdc++.h>

using namespace std;
char s[15], t[30];
vector<string> ans; int main(){
int n, x;
while(cin >> n){
ans.clear();
priority_queue<int, vector<int>, greater<int> > q;
for(int i = 0; i < n; ++i){
scanf("%s", s); if(s[0] == 'i'){
scanf("%d", &x);
sprintf(t, "insert %d", x);
ans.push_back(string(t));
q.push(x);
}
else if(s[0] == 'r'){
if(q.empty()){
ans.push_back("insert 1");
q.push(1);
}
ans.push_back("removeMin");
q.pop();
}
else{
scanf("%d", &x);
while(true){
if(q.empty() || q.top() > x){
q.push(x);
sprintf(t, "insert %d", x);
ans.push_back(string(t));
}
else if(q.top() == x){ break; }
else{
ans.push_back("removeMin");
q.pop();
}
}
sprintf(t, "getMin %d", x);
ans.push_back(string(t));
}
}
printf("%d\n", ans.size());
for(int i = 0; i < ans.size(); ++i)
cout << ans[i] << endl;
}
return 0;
}

CodeForces 681C Heap Operations (模拟题,优先队列)的更多相关文章

  1. Codeforces 681C. Heap Operations 优先队列

    C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  2. CodeForces 681C Heap Operations(模拟)

    比较简单的模拟,建议使用STL优先队列. 代码如下: #include<iostream> #include<cstdio> #include<cstring> # ...

  3. Codeforces Round #357 (Div. 2) C. Heap Operations 模拟

    C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...

  4. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces 691C. Exponential notation 模拟题

    C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

  6. CodeForces - 344B Simple Molecules (模拟题)

    CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...

  7. CodeForces - 344D Alternating Current (模拟题)

    id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...

  8. CodeForces - 344E Read Time (模拟题 + 二分法)

    E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. Heap Operations(模拟题)

     Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Windows Server 2012十大实用快捷键组合

    在本文中,我们将一起体验快捷键如何在微软最新服务器操作系统中帮助用户提升工作效率. 微软推出的最新服务器操作系统比我印象中任何一款前代Windows Server产品都依赖于键盘操作——当然,这些产品 ...

  2. OD 实验(二) - 绕过序列号验证

    需要破解的程序 输入用户名和序列号,点击 Check,程序会进行校验 用 OD 打开程序 按快捷键 Ctrl+F9 跟随表达式 GetDlgItemTextA 点击 ok 在这里调用了 GetDlgI ...

  3. 导出文件名带时间信息的dmp文件

    exp system/orcl@orcl owner=aixm file=d:\aixm%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2% ...

  4. Drools简单例子

    转自:http://www.blogjava.net/diggbag/articles/359347.html 1.Drools简单例子 首先是搭建一个可供进行Drools开发的框架.Jboss官方推 ...

  5. 「小程序JAVA实战」小程序的基础组件(24)

    转自:https://idig8.com/2018/08/12/xiaochengxu-chuji-24/ 来说下 ,小程序的基础组件.源码:https://github.com/limingios/ ...

  6. U3D 代码自动化生成定制预置体的旋转问题

    //定制预置体 //要求:1,模型面向U3D的Z轴正向(由MAX导出时是面向U3D的X负向的) //2,增加一些常用挂点,3增加一个圆形阴影片,4,添加包围盒 //根据这些要求制作预置休 static ...

  7. 【304】python专题-读取xml文件

    参考:XML DOM 参考手册(w3school) 参考:python专题-读取xml文件 参考:请问用python怎么修改xml的节点值? 1. 读取标签内的文本(Python) 如下的 xml 文 ...

  8. 译文:TypeScript新手指南

    你是否听过 TypeScript? TypeScript 是微软开发的 JavaScript 的超集,TypeScript兼容JavaScript,可以载入JavaScript代码然后运行.TypeS ...

  9. 后端生成二维码 - C#生成二维码(QR)

    最近在github上找到一个相对比较好的C#二维码生成类库.在这里和大家分享一下. github地址:https://github.com/codebude/QRCoder 把解决方案下载下来,编译生 ...

  10. a different object with the same identifier value was already associated with the session解决方案

    org.springframework.orm.hibernate3.HibernateSystemException: a different ]; nested exception ] at or ...