当前位置:网站首页>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++;
}
}
}
}
}
}
边栏推荐
- Top 10 in the 5.3 billion Bi Market: fansoft, Microsoft, Yonghong, sap, Baidu, IBM, SAS, smart, salesforce, Inspur soft
- [网摘][医学影像] 常用的DICOM缩略图解释以及Viewer converter 转换工具
- Synchronous use reference of the new version of data warehouse (for beginners)
- Solution: the idea project does not display a tree view
- NPM step pit
- Sword finger offer notes: T53 - I. find numbers in the sorted array
- 象棋机器人「弄折了」棋童的手指。。。
- Solution: can not issue executeupdate() or executelargeupdate() for selections
- Binary search decision tree (average search length of binary search tree)
- 解决方案:idea project没有显示树状图
猜你喜欢

Introduction to box diagram

解决@OneToMany查询陷入循环引用问题

Principle, concept and construction process of MySQL database master-slave replication cluster

快抖抢救“失意人”

上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质

Regular expression of shell programming (grep of shell script text three swordsmen)

LNMP architecture setup (deploy discuz Forum)

About the problem that the onapplicationevent method of the custom listener is executed multiple times

Watermelon Book + pumpkin book chapter 1-2

JS-寄生组合式继承
随机推荐
N ¨UWA: Visual Synthesis Pre-training for Neural visUal World creAtionChenfei
银行人脸识别系统被攻破:一储户被偷走 43 万元
USB network card drive data stream
Weibo comment crawler + visualization
Transactions in MySQL
Go replace with local code
Shell脚本文本三剑客之awk
Chapter 8 multithreading
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
Lonely young people can't quit jellycat
Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling
[网摘][医学影像] 常用的DICOM缩略图解释以及Viewer converter 转换工具
Alibaba cloud RDS exception during pool initialization
Packet transmission: application layer - kernel - hardware
Plus SBOM: assembly line BOM pbom
JVM memory model
go入门篇 (3)
系统临时文件的写和读:createTempFile和tempFileContent[通俗易懂]
Idea: can't use subversion command line client: SVN solution
SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series