比较简单的模拟,建议使用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. msmtp+mutt发送邮件报警

    1).yum 安装 msmtp+mutt yum install -y msmtp mutt 2).配置Muttrc信息 vim /etc/Muttrc set sendmail="/usr ...

  2. 《实战Java高并发程序设计》pdf

    花了我五元大洋,需要的拿去吧.百度云盘:https://pan.baidu.com/s/1o8bESY2

  3. 不自动切换eclipse视图

    刚开始使用eclipse进行调试时,当弹出"Confir Perspective Switch"视图时,不小心点了“No”.以后每次debug的时候都不切换到debug视图. 后发 ...

  4. 在自学php的路上不知道怎么走!!

    在自学php的路上不知道怎么走!! 真希望有人给我指点一二!!!

  5. jsp之用户自定义标签

    创建一个类,引入外部jsp-api.jar包(在tomcat 下lib包里有),这个类继承SimpleTagSupport 重写doTag()方法. jspprojec包下的helloTag类: pu ...

  6. HDU 2732 Leapin' Lizards

    网络最大流+拆点.输出有坑!!! #include<cstdio> #include<cstring> #include<string> #include<c ...

  7. Dell7040mt安装win7系统说明

    几天新买的Dell7040mt收到了,机器预装了win10系统,把win10作为开发平台,可能会有一些问题,所以改为win7,今天折腾了一天,终于把win7系统装上了.总结一下安装的步骤. 1 准备启 ...

  8. 三个JS函数闭包(closure)例子

    闭包是JS较难分辨的一个概念,我只是按自己的理解写下来,如有不对还请指出. 函数闭包是指当一个函数被定义在另一个函数内部时,这个内部函数使用到的变量会被封闭起来形成一个闭包,这些变量会保持形成闭包时设 ...

  9. GITLAB管理自己的私有源码

    github是很好的公开源码管理器,但是,私有项目,需要付费才行,比较郁闷,特别是个人工作者     gitlab(英文我不咋滴),上貌似允许1000个私有项目,其他的权限,还没怎么看,估计简单的项目 ...

  10. hdu_2608_0 or 1_数论

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2608 反正我是没找出这个规律的,规律参考的别人的! /* 分析:假设数n=2^k*p1^s1*p2^s ...