比较简单的模拟,建议使用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. Excel教程(2) - 函数的参数

    函数右边括号中的部分称为参数,假如一个函数可以使用 多个参数,那么参数与参数之间使用半角逗号进行分隔.参数 可以是常量(数字和文本).逻辑值(例如 TRUE 或 FALSE).数 组.错误值(例如#N ...

  2. jQuery控制表格行移动,序号不变

    @model Gd.NetSign.Controllers.DTO.SysPamaterDTO @{ ViewBag.Title = "SysPamatList"; //Layou ...

  3. 21.编写一个Java应用程序,该程序包括3个类:Monkey类、People类和主类 E。要求: (1) Monkey类中有个构造方法:Monkey (String s),并且有个public void speak() 方法,在speak方法中输出“咿咿呀呀......”的信息。 (2)People类是Monkey类的子类,在People类中重写方法speak(),在speak方法 中输出“小样

    //Monkey类 package d922; public class Monkey { Monkey() { } Monkey (String s) { System.out.println(s) ...

  4. ssh environment variable

    1 down vote When you run a command as an argument to ssh, the command is run directly by sshd; the s ...

  5. TextView赋值int型,并显示

    textview赋值int型采用text.setText(FPS+""); FPS为int型变量 或者在thread线程需要在主Activity中显示文字,可以调用: runOnU ...

  6. CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)

    B. New Year and North Pole time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. hadoop pig入门总结

    在这里贴一个pig源码的分析,做pig很长时间没做笔记,不包含任何细节,以后有机会再说吧 http://blackproof.iteye.com/blog/1769219 hadoop pig入门总结 ...

  8. 转:JMeter基础--逻辑控制器Logic Controller

    1.ForEach控制器 ForEach控制器在用户自定义变量中读取一系列相关的变量.该控制器下的采样器或控制器都会被执行一次或多次,每次读取不同的变量值.所以ForEach总是和User Defin ...

  9. VBS基础篇 - 循环语句(4) - For Each...Next

    VBS基础篇 - 循环语句(4) - For Each...Next   For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次 ...

  10. MFC创建动态链接库DLL并调用方法详解

    实例一: 1.创建一个动态链接库工程,如login_dll. 2.在原工程头文件或者新建头文件如showdlg.h定义动态链接库的导出函数,代码如下: #include "stdafx.h& ...