CodeForces 681C Heap Operations(模拟)
比较简单的模拟,建议使用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(模拟)的更多相关文章
- CodeForces 681C Heap Operations (模拟题,优先队列)
题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下 ...
- Codeforces 681C. Heap Operations 优先队列
C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #357 (Div. 2) C. Heap Operations 模拟
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...
- Heap Operations(模拟题)
Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #357 (Div. 2)C. Heap Operations
用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟....也没什么好说的.. #include<cstdio> #include<map> #i ...
- Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
随机推荐
- Chapter 14_4 使用_ENV
因为_ENV是一个普通的变量,我们可以像其他变量一样去对它进行赋值和访问. _ENV = nil 上面的赋值操作,将会使得在它之后的代码块不能直接访问全局变量.不过,对控制你的代码所使用的变量有用处. ...
- 4.编写Java应用程序。首先,定义一个时钟类——Clock,它包括三个int型 成员变量分别表示时、分、秒,一个构造方法用于对三个成员变量(时、分、秒) 进行初始化,还有一个成员方法show()用于显示时钟对象的时间。其次,再定义 一个主类——TestClass,在主类的main方法中创建多个时钟类的对象,使用这 些对象调用方法show()来显示时钟的时间。
Clock package com.hanqi.test; public class Clock { int hour,minute,second; Clock(int h,int m,int s) ...
- 【实验室笔记】C#上位机学习笔记
用C#编写上位机,基本流程是[1]串口配置,[2]串口发送数据,[3]串口接收数据. [1]串口配置 串口的属性配置包括: No.1串口端口号 No.2串口波特率 No.3串口数据位 No.4串口停止 ...
- Stash安装和破解
参考资料: http://www.unxmail.com/?p=590 上篇介绍了,Atlassian Stash v2.12.1 破解版的下载, 有同学不会安装. 我重新整理了下文档. 表述我的安装 ...
- ElasticSearch 的一次非正常master脱离的调查 (转 和我碰到的情况一模一样)
转自 http://simonlei.iteye.com/blog/1669992 一共有4个节点的cluster,其中es4 是master,某个时间突然es1脱离了整个cluster,调查过程如下 ...
- OpenVPN客户端解析
windows版本的VPN客户端,实际上就是一个外壳,创建了图形界面,托盘,和 右键菜单, 在connect的动作里,实际上是通过cmd调用 openvpn.exe openvpn --config ...
- selenium 百度登陆
using System;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;//引用命名空间using System.IO; using Syst ...
- Myeclipse8.6安装freemarker插件
1. 打开http://sourceforge.net/projects/freemarker-ide/files/ 下载最新版本,目前本人下载时最新版本是:freemarker-ide-0.9.14 ...
- xib storyboard
initWithNibName加载xib或者storyboard BLEViewController *controller = [[BLEViewController alloc] initWith ...
- english 释词
english 释词 [amount of & number of]the amount of /the number of指……的数量an amount of/a number of 指“大 ...