CodeForces 681C Heap Operations(模拟)】的更多相关文章

题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下队列是不是空的,然后再考虑getMin,这个是不是对应的值,如果队列中首元素比它大,那么就加上一个, 如果相等直接取出,如果小于就不断取队列中最小元素. 代码如下: #include <bits/stdc++.h> using namespace std; char s[15], t[30]; v…
C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following…
比较简单的模拟,建议使用STL优先队列. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; #define N 1000010 ]; int outn[N]; priority_queue<int,vector<int>,greater<int> >que; int main()…
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following operations: put the given number into the…
 Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following o…
用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟....也没什么好说的.. #include<cstdio> #include<map> #include<queue> #include<iostream> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; priority_queu…
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记录\(b_i\)在\(a_i\)中的位置,然后枚举\(b_i\),取它在\(a_i\)的位置,然后看\(a_{i-1}\)和\(a_{i+1}\)的情况,因为我们append之后必须要删除\(a_{i-1}\)和\(a_{i+1}\)中的一个,并且所有元素都是不重复的,所以\(a_{i-1}\)和\…
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard input output: standard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships…
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U'…
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人只能打招呼一次). 例: 输入:31 1 105 8 29 9 10 输出: 2 1 1 解题思路:先按行走的开始时刻排下序,然后直接模拟判断和比他后出现的人是否可以相遇. 第一步判断前面那个人在未走完前,下一人会出现,若不出现,直接break.然后就计算当下一个人出现的时刻,前一个人的位置,然后又…