当前位置:网站首页>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;
}
边栏推荐
- Uniform Asymptotics by Alexei
- Future & CompletionService
- ECMAScript 6(es6)
- ECMAScript 6(es6)
- Institute of Microbiology, Chinese Academy of Sciences recruited 20 young PI, with a resettlement fee of 2million yuan and a start-up fund of 10million yuan (long-term effective)
- 微软云 (Microsoft Cloud) 技术概述
- Feedforward feedback control system design (process control course design matlab/simulink)
- Privacy computing fat offline prediction
- 【TcaplusDB知识库】TcaplusDB OMS业务人员权限介绍
- .NET6接入Skywalking链路追踪完整流程
猜你喜欢

如何在 Methodot 中部署 JupyterLab?

15+城市道路要素分割应用,用这一个分割模型就够了!

NVME2.0协议——新特性

以后发现漏洞,禁止告诉中国!

Metadata of database
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)](/img/04/b1194ca3340b23a4fb2091d1b2a44d.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)

【TcaplusDB知识库】TcaplusDB运维单据介绍

Code for structural design of proe/creo household appliances - electric frying pan

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

面试突击60:什么情况会导致 MySQL 索引失效?
随机推荐
[cloud enjoys freshness] community weekly · vol.68- Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + business realization
[tcapulusdb knowledge base] Introduction to tcapulusdb data import
杰理之增加一个输入捕捉通道【篇】
【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
机器学习系统在生产中的挑战
在外企远程办公是什么体验? | 社区征文
Feedforward feedback control system design (process control course design matlab/simulink)
【值得收藏】Centos7 安装mysql完整操作命令
Leetcode 729. 我的日程安排表 I(牛逼,已解决)
Oracle group statistics query
Queue, two-way queue, and its application
中科院微生物所招聘青年PI 20位,2百万安家费,千万启动经费(长期有效)
Proe/Creo家电产品结构设计规范-电煎锅
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching
Microsoft cloud technology overview
一篇抄十篇,CVPR Oral被指大量抄袭
【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
KDD 2022 | epileptic wave prediction based on hierarchical graph diffusion learning
ECMAScript 6(es6)
Glide caching mechanism