当前位置:网站首页>2021-3-23-meituan-priority queue
2021-3-23-meituan-priority queue
2022-07-27 12:18:00 【Anethole job】
Title Description :
The canteen of Xiaomei and Xiaotuan's company has N A dining table ,
Form a row from left to right , Each table has 2 Dining chairs for up to 2 People eat ,
Company staff lined up to eat in the canteen . Xiaomei found a rule of staff dining and told Xiaotuan :
When the male staff entered the canteen , He will give priority to those who already sit 1 People's dining table , Only when each table is either empty or full 2 Human hour , He'll think about an empty table ;
When the female staff entered the canteen , She will prefer the uninhabited table , Only if every table has at least 1 Human hour , She'll think about having 1 Human table ;
Both men and women , When there are multiple tables for staff to choose from , He will choose the leftmost table . Now there are several people eating in the canteen , in addition M People are lining up to enter the canteen , Xiaotuan will predict which table everyone in line will sit at according to the law Xiaomei told him .
Input description :
Enter an integer in the first line T(1<=T<=10), Represents the number of data groups .
Each group of data consists of four rows , Enter an integer in the first line N(1<=N<=500000);
On the second line, enter a length of N And contains only numbers 0、1、2 String , The first i A number indicates the... From the left i The number of people sitting at this table ;
Enter an integer in the third line M(1<=M<=2N And ensure that everyone in line has an alternative table when entering the canteen );
On the fourth line, enter a length of M And contains only the letters M、F String , Ruodi i The letters are M, Is ranked No i People are men , Otherwise it's female .
Output description :
Each group of data output accounts for M That's ok , The first i Line outputs an integer j(1<=j<=N), Means to be in the i People will choose the first from the left j Eat at a table .
Example 1
Input
1
5
01102
6
MFMMFF
Output
2
1
1
3
4
4
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int T = 0;
cin >> T;
for (int k = 0; k < T; k++)
{
int N , M ;
cin >> N;
string desk, que;
cin >> M;
cin >> desk;
cin >> que;
int f_zero = -1, f_one = -1;
for (int i = 0; i < N; i++)
{
if (f_zero == -1 && f_one == -1)
{
break;
}
else if (f_zero == -1 && desk[i] == '0')
{
f_zero = i;
}
else if (f_one == -1 && desk[i] == '1')
{
f_one = i;
}
}
for (int i = 0; i < M; i++)
{
if (que[i] == 'M')
{
// When the male staff entered the canteen , Will give priority to what has been done 1 People's dining table
if (f_one < N)
{
cout << f_one + 1 << endl;
desk[f_one] = '2';
while (f_one < N && desk[f_one] != '1')
{
f_one++;
}
}
else
{
// Only when each table is either empty or full 2 people , He'll think about an empty table
cout << f_zero + 1 << endl;
desk[f_zero] = '1';
if (f_zero < f_one)
{
f_one = f_zero;
}
while (f_zero < N && desk[f_zero] != '0')
{
f_zero++;
}
}
}
else
{
// When the female staff entered the canteen , Will give priority to the table without being human
if (f_zero < N)
{
cout << f_zero + 1 << endl;
desk[f_zero] = '1';
while (f_zero < N && desk[f_zero] != '0')
{
f_zero++;
}
}
else
{
// Only when every table is only made 1 Human hour , She thought it was full 1 Human table
cout << f_one + 1 << endl;
desk[f_one] = '2';
while (f_one < N && desk[f_one] != '1')
{
f_one++;
}
}
}
}
}
}
边栏推荐
- Shake quickly to rescue the "frustrated person"
- compute_ class_ weight() takes 1 positional argument but 3 were given
- Solution: can not issue executeupdate() or executelargeupdate() for selections
- Go Beginner (4)
- mysql8msi安装教程(数据库mysql安装教程)
- Solution: the idea project does not display a tree view
- NewTicker使用
- Ali II: what if the AOF file in redis is too large?
- JS字符串方法总结
- Top 10 in the 5.3 billion Bi Market: fansoft, Microsoft, Yonghong, sap, Baidu, IBM, SAS, smart, salesforce, Inspur soft
猜你喜欢

TapNet: Multivariate Time Series Classification with Attentional Prototypical Network

快抖抢救“失意人”
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!

iptables防火墙

Alibaba cloud RDS exception during pool initialization

Makefile template

孤独的年轻人,戒不了Jellycat

Solution: can not issue executeupdate() or executelargeupdate() for selections

MySQL数据库主从复制集群原理概念以及搭建流程

广东:剧本杀等新行业新业态场所,消防安全监管不再“缺位”
随机推荐
About offline caching application cache / using manifest file caching
20210408 longest public prefix
[excerpt] [medical image] common DICOM thumbnail interpretation and viewer converter conversion tool
Sword finger offer notes: t57 - ii Continuous positive sequence with sum s
TapNet: Multivariate Time Series Classification with Attentional Prototypical Network
JS字符串方法总结
Example of MATLAB dichotomy (example of finding zero point by dichotomy)
CLS 监控告警:实时保障线上服务高可用性
Sword finger offer notes: t58 - ii Rotate string left
Shell script text three swordsmen sed
Leetcode 04: T26. Delete duplicate items in the sorting array (simple); Sword finger offer 67. convert the string to an integer (medium); Interview question 01.08. zero matrix (simple)
解决@OneToMany查询陷入循环引用问题
Newticker uses
Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
The first case of monkeypox in pregnant women in the United States: the newborn was injected with immunoglobulin and was safely born
Detailed explanation of flask framework
Solution: the idea project does not display a tree view
Do you really understand the underlying data structure skip list of Zset in redis?
mysql8msi安装教程(数据库mysql安装教程)
Detailed explanation of flask framework