当前位置:网站首页>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;
}
边栏推荐
- Glide caching mechanism
- Privacy computing fat offline prediction
- Write it down once Net analysis of a property management background service stuck
- VPT Model Video Explanation
- Deep understanding of happens before principle
- Ci/cd automatic test_ 16 best practices for CI / CD pipeline to accelerate test automation
- Error im002 when Oracle connects to MySQL
- How to deploy jupyterlab in methodot?
- LLVM系列(1)- LLVM简介
- Ubuntu手动安装MySQL
猜你喜欢

【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(一)

【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)

One copy ten, CVPR oral is accused of plagiarizing a lot

Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training

How to deploy jupyterlab in methodot?

政策关注 | 加快构建数据基础制度,维护国家数据安全

Future & CompletionService

KDD 2022 | 基于分层图扩散学习的癫痫波预测

Codeforces Round #786 (Div. 3) ABCDE

Metadata of database
随机推荐
【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool
Learning notes - data set generation
微软云 (Microsoft Cloud) 技术概述
[cloud enjoys freshness] community weekly · vol.68- Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + business realization
【TcaplusDB知识库】Tmonitor系统升级介绍
Leetcode 729. My schedule I (provides an idea)
Ubuntu手動安裝MySQL
政策关注 | 加快构建数据基础制度,维护国家数据安全
软交换呼叫中心系统的支撑系统
Concepts of concurrency, parallelism, asynchronism, synchronization, multithreading and mutual exclusion
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
VPT模型视频讲解
飞桨产业级开源模型库:加速企业AI任务开发与应用
Feedforward feedback control system design (process control course design matlab/simulink)
堆-堆排序-TopK
Audiotrack and audiolinker
【TcaplusDB知识库】TcaplusDB数据构造介绍
Working at home is more tiring than going to work at the company| Community essay solicitation
File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument