比较简单的模拟,建议使用STL优先队列。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define N 1000010
char outs[N][];
int outn[N];
priority_queue<int,vector<int>,greater<int> >que;
int main()
{
int n,num;
int tot = ;
while(!que.empty()) que.pop();
char op[];
scanf("%d",&n);
getchar();
while(n--)
{
scanf("%s",op);
if(!strcmp(op,"insert"))
{
scanf("%d",&num);
strcpy(outs[tot],op);
outn[tot++] = num;
que.push(num);
}
else if(!strcmp(op,"removeMin"))
{
if(que.empty())
{
strcpy(outs[tot],"insert");
outn[tot++] = ;
que.push();
}
strcpy(outs[tot],op);
outn[tot++] = -;
que.pop();
}
else if(!strcmp(op,"getMin"))
{
scanf("%d",&num);
bool have = false;
while(!que.empty())
{
int tmp = que.top();
if(tmp < num)
{
strcpy(outs[tot],"removeMin");
outn[tot++] = -;
que.pop();
}
if(tmp == num)
{
have = true;
break;
}
if(tmp > num) break;
}
if(!have)
{
strcpy(outs[tot],"insert");
outn[tot++] = num;
que.push(num);
}
strcpy(outs[tot],"getMin");
outn[tot++] = num;
}
}
printf("%d\n",tot);
for(int i = ; i < tot; i++)
{
if(!strcmp(outs[i],"removeMin")) printf("%s\n",outs[i]);
else printf("%s %d\n",outs[i],outn[i]);
}
return ;
}

CodeForces 681C Heap Operations(模拟)的更多相关文章

  1. CodeForces 681C Heap Operations (模拟题,优先队列)

    题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下 ...

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

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

  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. Heap Operations(模拟题)

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

  5. Codeforces Round #357 (Div. 2)C. Heap Operations

    用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟....也没什么好说的.. #include<cstdio> #include<map> #i ...

  6. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  7. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  8. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  9. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

随机推荐

  1. VC 中使用 CToolTipCtrl 消失后不再出现的Bug。。。。

    最近用WTL重写CGdipButton.从ButtonST中将CtoolTipCtrl的相关代码转过来,发现一个问题: ToolTip可以显示,鼠标移开后再移动到button上也可以再次显示,但是按下 ...

  2. WebService 调用三种方法

    //来源:http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html 最近做一个项目,由于是在别人框架里开发app,导致了很多限制 ...

  3. iOS动画编程

    IOS中的动画总结来说有五种:UIView<block>,CAAnimation<CABasicAnimation,CATransition,CAKeyframeAnimation& ...

  4. 锅巴H264播放器地址和说明

    锅巴H264播放器地址和说明 软件说明:  此工具专门用来播放安防监控行业的H264录像文件,不管是哪个设备厂家的视频协议,只要您的录像文件里有 H264数据,就可以播放. 备注: 因为被一些事情的影 ...

  5. sql存储过程——名称 ****不是有效的标识符

    转载自http://blog.csdn.net/xb12369/article/details/8202703 假设存储过程:proc_test create proc proc_test @Prod ...

  6. HTML+CSS Day10实例

    1.家居大视野 效果图: 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  7. UVALive - 3026 Period kmp next数组的应用

    input n 2<=n<=1000000 长度为n的字符串,只含小写字母 output Test case #cas 长度为i时的最小循环串 循环次数(>1) 若没有则不输出 做法 ...

  8. Hibernate查询、连接池、二级缓存

    Hibernate第三天: 1. 对象状态 2. session缓存 3. lazy懒加载 4. 映射 一对一对映射 组件/继承映射 目标: 一.hibernate查询 二.hibernate对连接池 ...

  9. 【3】docker命令集

    root@xcc-VirtualBox:/home/xcc# docker --helpUsage: docker [OPTIONS] COMMAND [arg...]       docker [ ...

  10. VI/VIM 常用命令

    VI/VIM 常用命令=========== 整理自鸟哥的私房菜 ---------- - 移动光标 命令                    | 描述----------------------- ...