当前位置:网站首页>AcWing 132. Group queue (queue simulation question)
AcWing 132. Group queue (queue simulation question)
2022-06-12 10:40:00 【Jacob* ̄▽ ̄*】





The question :
Yes n A group Queue up , There are several people in each group .
When a man comes to the team ,
- If The team already has members of its own team , He just jumped in line behind his team members .
- otherwise , Standing at the back of the line .
Given No more than 2 * 10 ^ 5 Order to join the team ( The number is X People who Come to the team ) and Out of line instructions ( Team leader Out of the team ), Output The order of leaving the team .
Ideas :
This problem obviously needs a lot of Small queues , So for the convenience of , Let's go straight ahead N individual queue As Total queue , namely queue<int>[N]
Use one Hashtable ha, Record All entered member numbers Of Group number .
Use one Array st, Record Enter the group to which the member belongs Whether it appears in The total queue in , If by 0 There has never been , Not for 0 Record at the same time The group Appear in the What paragraph Small queues In .
Then the simulation , See code for details .
Be careful :
- Out of the team When , When The size of a small queue is
0Be sure to remember tostArray Corresponding place clear0.
Code :
#define _CRT_SECURE_NO_WARNINGS 1
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
map<int, int> ha;// The group number corresponding to the member number
int st[N];// Determine whether members of a group appear in the queue , At the same time, record the group in the sub queue of the group
int main()
{
int T = 1;
int Cnt = 0;
while (~scanf("%d", &T), T)
{
queue<int> qq[N];
memset(st, false, sizeof st);
ha.clear();
int h = 1, t = 0;
while (T--)
{
int cnt; scanf("%d", &cnt);
++t;
for (int i = 0; i < cnt; ++i)
{
int tag; scanf("%d", &tag);
ha[tag] = t;
}
}
char op[20];
h = 1, t = 0;
printf("Scenario #%d\n", ++Cnt);
while (~scanf("%s", op), *op != 'S')
{
if (*op == 'E')
{
int x; scanf("%d", &x);
//cout << "ha[x] " << ha[x] << '\n';
// When there is no... In the total queue x Members of the group to which they belong , Then open a new small queue and press x
if (!st[ha[x]])
{
st[ha[x]] = ++t;
qq[t].push(x);
}
else // Otherwise, they will be pushed into the small queue of their group
{
qq[st[ha[x]]].push(x);
}
}
else
{
if (qq[h].size())
{
int top = qq[h].front();
printf("%d\n", top);
qq[h].pop();
if (!qq[h].size())
{
st[ha[top]] = 0;
h++;
}
}
}
}
puts("");
}
return 0;
}
边栏推荐
- file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
- LVS基于应用层的健康状态检测
- Introduction to encoding formats (ASCII, Unicode and UTF-8)
- The name of a great man
- M-Arch(番外12)GD32L233评测-CAU加解密(捉弄下小编)
- 2022京東618預售定金怎麼退?京東618定金能退嗎?
- Is the acceptance standard a test case?
- 2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills
- Leetcode 2169. 得到 0 的操作数
- PHP Apple purchase verification steps
猜你喜欢

Leetcode 2169. 得到 0 的操作数

Malicious code analysis practice - use IDA pro to analyze lab05-01 dll

On the improvement of 3dsc by harmonic shape context feature HSC

Summary method of lamp environment deployment

How to upload the video on the computer to the mobile phone without network

AcWing 131. 直方图中最大的矩形(单调栈经典运用 模板)

Solution to invalid small program scroll into view

Fiddler automatically saves the result of the specified request to a file

浅谈三维形状上下文特征3DSC理论及应用

Valentina Studio Pro for MAC (MAC database management software)
随机推荐
Download Notepad++
命名规范/注释规范/逻辑规范
Simple use of autojs
MYSQL——内置函数
Composer command
golang中的定时器
基于QT的旅行查询与模拟系统
Common tools download address
PHP specifies the number of people to distribute the specified amount equally at random (scaling method)
元宇宙系统搭建与构造
Timers in golang
Summary method of lamp environment deployment
【CF1392D】D. Omkar and Bed Wars(环形与后效性dp)
Using the echart plug-in to dynamically refresh charts in uview/uni-app
This and final keywords
Grid layout
Introduction to encoding formats (ASCII, Unicode and UTF-8)
How the ArrayList collection implements ascending and descending order
Set SVG color
AcWing 135. Maximum subsequence sum (prefix sum + monotone queue to find the minimum value of fixed length interval)