当前位置:网站首页>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;
}
边栏推荐
- 【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
- istio相关资料
- 居家办公竟比去公司上班还累? | 社区征文
- Red envelope rain: a wonderful encounter between redis and Lua
- 【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
- [tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)
- 杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
- Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
- 【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
- Oracle-分组统计查询
猜你喜欢

Leetcode 729. 我的日程安排表 I(牛逼,已解决)

Codeforces Round #786 (Div. 3) ABCDE

Glide缓存机制

Future & CompletionService

【TcaplusDB知识库】TcaplusDB常规单据介绍

Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)

TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.1 生成树协议(Spanning Tree Protocol (STP))
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)](/img/04/b1194ca3340b23a4fb2091d1b2a44d.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)

记一次 .NET 某物管后台服务 卡死分析

【TcaplusDB知识库】Tmonitor系统升级介绍
随机推荐
Working at home is more tiring than going to work at the company| Community essay solicitation
iMeta:高颜值绘图网站imageGP+视频教程合集,已被引360次(220625更新)
Evolution of software system architecture
Co jump
20 jeunes Pi recrutés par l'Institut de microbiologie de l'Académie chinoise des sciences, 2 millions de frais d'établissement et 10 millions de fonds de démarrage (à long terme)
红包雨: Redis 和 Lua 的奇妙邂逅
嵌入式软件架构设计-模块化
Metadata of database
Oracle multi table query
Installation manuelle de MySQL par UBUNTU
Memory compression for win10
Privacy computing fat offline prediction
【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
Uniform Asymptotics by Alexei
Glide caching mechanism
隐私计算FATE-离线预测
[methodot topic] what kind of low code platform is more suitable for developers?
Eureka core source code analysis
Based on swift admin's rapid background development framework, I made a rookie tutorial [professional version]
【TcaplusDB知识库】TcaplusDB系统管理介绍