当前位置:网站首页>Informatics Olympiad all in one 1332: [example 2-1] weekend dance
Informatics Olympiad all in one 1332: [example 2-1] weekend dance
2022-06-27 11:04:00 【Junyi_ noip】
【 Topic link 】
ybt 1332:【 example 2-1】 Weekend dance
【 Topic test site 】
1. queue
【 Their thinking 】
Use two queues to simulate two teams of men and women , Let the two teams join the team first .
The number of dances is n.
Let the two teams go out each time 1 people , The two danced in pairs , Output the numbers of these two people .
Then the two men who left the team joined the team to the end of the team , Go back to your line .
So circular n Time .
【 Solution code 】
solution 1: Using arrays and expressions to implement queues
#include <bits/stdc++.h>
using namespace std;
#define N 1005
int que_m[N], que_f[N];// Two queues
int h_m, t_m, h_f, t_f;// The head and tail pointers of the two queues
int main()
{
int m, f, temp_m, temp_f, n;//m,f: Number of men and women temp_m, temp_f: The male and female numbers of the temporary team n: Number of dances
cin >> m >> f >> n;
for(int i = 1; i <= m; ++i)// Men join the team
que_m[++t_m] = i;
for(int i = 1; i <= f; ++i)// Ladies join the team
que_f[++t_f] = i;
for(int i = 1; i <= n; ++i)
{
temp_m = que_m[++h_m];// men 's team , Women's teams go out 1 people
temp_f = que_f[++h_f];
cout << temp_m << ' ' << temp_f << endl;
que_m[++t_m] = temp_m;// Put two people out of the team back into the team
que_f[++t_f] = temp_f;
}
return 0;
}
solution 2: Use C++ STL
#include <bits/stdc++.h>
using namespace std;
int main()
{
queue<int> q1, q2;//q1: Men's queue q2: Ladies line up
int a, b, n;
cin >> a >> b >> n;
for(int i = 1; i <= a; ++i)
q1.push(i);
for(int i = 1; i <= b; ++i)
q2.push(i);
for(int i = 1; i <= n; ++i)
{
cout << q1.front() << ' ' << q2.front() << endl;// The heads of the two teams came out to dance in pairs
q1.push(q1.front());// Put the value of the team leader in the team to the end of the team
q1.pop();// Team leader out of team
q2.push(q2.front());
q2.pop();
}
return 0;
}
边栏推荐
- What basic functions are required for live e-commerce application development? What is the future development prospect?
- 【TcaplusDB知识库】TcaplusDB OMS业务人员权限介绍
- 如何在 Methodot 中部署 JupyterLab?
- 15+城市道路要素分割应用,用这一个分割模型就够了!
- [tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
- ECMAScript 6(es6)
- 【TcaplusDB知识库】TcaplusDB-tcaplusadmin工具介绍
- Oracle trigger stored procedure writes at the same time
- [tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)
- Co jump
猜你喜欢
![File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument](/img/08/2d4f425e6941af35616911672b6fed.png)
File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument

Ci/cd automatic test_ 16 best practices for CI / CD pipeline to accelerate test automation

杰理之串口通信 串口接收IO需要设置数字功能【篇】
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)](/img/04/b1194ca3340b23a4fb2091d1b2a44d.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)
![[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction](/img/85/39e54ebc613f6d1dc7f02168adaaee.png)
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction

【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍

【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍

Feedforward feedback control system design (process control course design matlab/simulink)

Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)

【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
随机推荐
Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
【TcaplusDB知识库】TcaplusDB单据受理-事务执行介绍
[learn FPGA programming from scratch -47]: Vision - current situation and development trend of the third generation semiconductor technology
Audiotrack and audiolinker
【TcaplusDB知识库】TcaplusDB运维单据介绍
嵌入式软件架构设计-模块化
istio相关资料
杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
Co jump
Glide缓存机制
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
深入理解 happens-before 原则
[从零开始学习FPGA编程-47]:视野篇 - 第三代半导体技术现状与发展趋势
数据库之元数据
Change PIP mirror source
[tcapulusdb knowledge base] tcapulusdb cluster management introduction
直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?
【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
堆-堆排序-TopK
Microsoft cloud technology overview