I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. 2 Take out an element from the bag. Given a sequence of operations with return values, you're going to guess the data…
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结构,可以用三个标志变量来标志可能的数据结构. 注意:可能会出现数据结构为空的情况,要先判断非空才能取元素. AC代码 #include <stdio.h> #include <stack> #include <queue> using namespace std; //分别…
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. 2 Take out an element from the bag. Given a sequence of operations with return values, you're going to guess the data…
11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. 2 Take out an element from the bag. Given…
There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. 2 Take out an element from the bag. Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-I…
题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h> using namespace std; int main(void) { int n; while (scanf ("%d", &n) == 1) { stack<int> sta; queue<int> que; priority_queue&…
做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include <bits/stdc++.h> using namespace std; void scan( int &x ) { char c; ' ); x = c - '; + c - '; } + ; int t[maxn], d[maxn]; bool is_queue(int n) { q…
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> using namespace std; int n; ],u[]; int ck_q() { //cout<<"!!"<<endl; queue<int>s; ; i<n;…
树状数组   查询操作:O(logn) 修改操作:O(logn) #define lowbit(x) (x & -x) int tr[N]; // 树状数组 // 添加c个大小为x的数值 void add(int x, int c) { for(int i = x; i <= n; i += lowbit(i)) tr[i] += c; } // 求数值大小在1~x的数值的和 int sum(int x) { int res = 0; for(int i = x; i; i -= lowbi…
11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations:1 x Throw an element x into the bag.2 Take out an element from the bag.Given a sequence of operations with return values, you’re going to guess the…