比较简单的模拟,建议使用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. 洛谷-哥德巴赫猜想(升级版)-BOSS战-入门综合练习1

    题目背景 Background 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇数都可以表示成3个质数之和.质数是指除了1和本身之外没有其他约数的数,如2和 ...

  2. Openjudge-计算概论(A)-判断闰年

    描述: 判断某年是否是闰年.输入输入只有一行,包含一个整数a(0 < a < 3000)输出一行,如果公元a年是闰年输出Y,否则输出N样例输入 2006 样例输出 N 提示:公历纪年法中, ...

  3. Sersync同步过滤.svn文件夹

    Sersync同步过滤.svn文件夹 <filter start="true"> <exclude expression="(.*).svn(.*)&q ...

  4. 安卓手机微信页面position: fixed位置错误

    今天做项目的时候发现动用position: fixed做弹窗时,用margin-top:50%这样外边距来响应式的控制位置时,在微信里打开页面的弹窗,弹窗在手机上显示的位置和实际上在手机上的位置不一样 ...

  5. iphone下元素放在了一个position: fixed的div中无法点击

    网上的说法是这样的: iphone的浏览器有这么一个bug, 当你使用锚定或滚动页面后, 你会发现某些东西不能点击了! 如果你的这个“东西”放在了一个position: fixed的div中, 那么你 ...

  6. log4j2日志

    log4j2.xmllog4j-api-2.5.jarlog4j-core-2.5.jar <?xml version="1.0" encoding="UTF-8& ...

  7. APP测试--功能测试

    1.1 了解需求 这一点,不但是功能测试,是所有测试都需要的第1步.通过需求文档,与产品经理的沟通,与开发的沟通,用户的使用习惯等各方法,了解APP的需求. 1.2 编写测试用例 当然之前可能是测试计 ...

  8. C++ : 从栈和堆来理解C#中的值类型和引用类型

    C++中并没有值类型和引用类型之说,标准变量或者自定义对象的存取默认是没有区别的.但如果深入地来看,就要了解C++中,管理数据的两大内存区域:栈和堆. 栈(stack)是类似于一个先进后出的抽屉.它的 ...

  9. jsp之用户自定义标签

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

  10. pur-ftpd在ubuntu上的安装2(数据库管理)

    1.安装mysql数据库支持的pure-ftpd apt-get install pure-ftpd-mysql 2.添加分组"ftpgroup",并且添加分组虚拟用户" ...