随笔分类 - 队列
队列
摘要:一、普通队列 // hh 表示队头,tt表示队尾 int q[N], hh = 0, tt = -1; // 向队尾插入一个数 q[ ++ tt] = x; // 从队头弹出一个数 hh ++ ; // 队头的值 q[hh]; // 判断队列是否为空 if (hh <= tt) { } 二、循环队列
阅读全文
摘要:## . 模拟队列 一、题目描述 实现一个队列,队列初始为空,支持四种操作: push x – 向队尾插入一个数 x; pop – 从队头弹出一个数; empty – 判断队列是否为空; query – 查询队头元素。 现在要对队列进行 个操作,其中的每个操作 $3
阅读全文
摘要:题目传送门 c++ 代码 #include <bits/stdc++.h> using namespace std; int n, t, k, x; //国籍的桶 unordered_map<int, int> _map; int res; struct person { int nation; /
阅读全文
摘要:题目传送门 C++代码 #include <bits/stdc++.h> using namespace std; const int N = 1010; int m, n, cnt; //思路:队列+桶 bool b[N]; //判断该数是否在内存中,桶。 queue<int> q; //定义一个
阅读全文
摘要:题目传送门 理解与感悟 用队列思想解决约瑟夫问题是最直白的,看来不管是哪个问题,都有一种最合适的解法。 #include <bits/stdc++.h> using namespace std; int n, m; queue<int> q; int main() { //读入n个人,数到m的人 c
阅读全文