Codeforces Round #357 (Div. 2)C. Heap Operations
用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟。。。。也没什么好说的。。
#include<cstdio>
#include<map>
#include<queue>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> >qq;
struct asd{
char s[10];
int k;
};
asd q[500000];
int main()
{
int n;
scanf("%d",&n);
int x;
char ss[10];
int num=0;
for(int i=0;i<n;i++)
{
scanf("%s",&ss);
if(ss[0]=='i')
{
scanf("%d",&x);
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x);
}
else if(ss[0]=='r')
{
int s1,s2;
if(!qq.empty())
{
s1=qq.top();
strcpy(q[num].s,"removeMin");
q[num].k=s1;
num++;
qq.pop();
}
else
{
strcpy(q[num].s,"insert");
q[num].k=0;
num++;
strcpy(q[num].s,"removeMin");
q[num].k=0;
num++;
}
}
else if(ss[0]=='g')
{
scanf("%d",&x);
int s1;
if(!qq.empty())
{
s1=qq.top();
if(s1==x)
{
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
else if(s1>x)
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x);
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
else if(s1<x)
{
int flag=0;
while(!qq.empty())
{
int nn=qq.top();
if(nn==x)
{
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
break;
}
else if(nn>x)
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x);
strcpy(q[num].s,"getMin");
q[num].k=x;
flag=1;
num++;
break;
}
else if(nn<x)
{
strcpy(q[num].s,"removeMin");
q[num].k=nn;
num++;
qq.pop();
}
}
}
}
if(qq.empty())
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x);
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
}
}
printf("%d\n",num);
for(int i=0;i<num;i++)
{
if(q[i].s[0]=='r')
{
printf("%s\n",q[i].s);
}
else
{
printf("%s %d\n",q[i].s,q[i].k);
}
}
return 0;
}
/*
2
insert
getMin 4
8
insert 1
insert 1
insert 1
removeMin
removeMin
removeMin
getMin 2
getMin 3
13
insert -851839419
removeMin
removeMin
g
/*
2
insert
getMin 4
8
insert 1
insert 1
insert 1
removeMin
removeMin
removeMin
getMin 2
getMin 3
13
insert -851839419
removeMin
removeMin
getMin -624068418
insert 119194510
removeMin
removeMin
removeMin
getMin -179673992
getMin 520596304
insert -265233646
getMin -222234500
removeMin
6
insert 1
insert 1
insert 1
removeMin
getMin 6
getMin 3
4
getMin 4
getMin 3
getMin 2
getMin 1
4
getMin 1
getMin 2
getMin 3
getMin 4
*/
Codeforces Round #357 (Div. 2)C. Heap Operations的更多相关文章
- Codeforces Round #357 (Div. 2) C. Heap Operations 模拟
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...
- Codeforces Round #357 (Div. 2) 优先队列+模拟
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) C
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何
E. Runaway to a Shadow 题目连接: http://www.codeforces.com/contest/681/problem/E Description Dima is liv ...
- Codeforces Round #357 (Div. 2) D. Gifts by the List 水题
D. Gifts by the List 题目连接: http://www.codeforces.com/contest/681/problem/D Description Sasha lives i ...
- Codeforces Round #357 (Div. 2) B. Economy Game 水题
B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...
- Codeforces Round #357 (Div. 2) A. A Good Contest 水题
A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...
- Codeforces Round #357 (Div. 2) A
A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #357 (Div. 2) E 计算几何
传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...
随机推荐
- Android开发Tips(3)
欢迎Follow我的GitHub, 关注我的CSDN. 我会介绍关于Android的一些有趣的小知识点. 本文是第三篇, 其余第一篇, 第二篇. imageMogr2/auto-orient/stri ...
- BoW(SIFT/SURF/...)+SVM/KNN的OpenCV 实现
本文转载了文章(沈阳的博客),目的在于记录自己重复过程中遇到的问题,和更多的人分享讨论. 程序包:猛戳我 物体分类 物体分类是计算机视觉中一个很有意思的问题,有一些已经归类好的图片作为输入,对一些未知 ...
- UltraEdit中使用正则表达式-简单用法
UltraEdit中使用正则表达式 1.认识正则表达式语法: 正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串 ...
- OO的片段,继承与组合,继承的优点与目的,虚机制在构造函数中不工作
摘自C++编程思想: ------------------------------ 继承与组合:接口的重用 ------------------------------- 继承和组合都允许由已存在的类 ...
- Windows下VMware虚拟机使用Centos,Docker方式安装openstf的小坑
今天使用docker方式安装openstf碰到了一小坑,坑了我半天.特此记录! docker方式安装stf就不说了,网上教程一大把. 但是... 安装完之后.进入web控制界面,手机连接的好好的.但硕 ...
- Node安装及搭建简单HTTP服务器
注:本文安装系统为mac,windows及其他系统下载对应安装包 ,mac下载后的安装包为apk文件,windows为msi文件. 安装 1.在网上下载node安装包,官方网站2.双击下载文件,按步骤 ...
- gnss到底是什么呢
GNSS Global Navigation Satellite System 全球卫星导航系统:提到这个很多人会不明白GNSS倒是是个啥东西呢,和北斗,GPS, GLONASS,Galileo系统有 ...
- HDU1358 Period —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- CentOS/Ubuntu安装GLIBCXX3.4.21
经过测试“GLIBCXX3.4.21 not find”这篇博文解决了我的问题. 以下是安装步骤: 一.首先查看当前gcc版本 strings /usr/lib/x86_64_linux-gun/ ...
- CSS自定义文件上传按钮样式,兼容主流浏览器
解决办法:使用text文本框及a链接模拟文件上传按钮,并且把文件上传按钮放在他们上面,并且文件上传按钮显示透明.1.图片2. [代码][HTML]代码 <div class="b ...