当前位置:网站首页>上课笔记(6)(2)——#742. 周末舞会
上课笔记(6)(2)——#742. 周末舞会
2022-08-04 23:19:00 【xyc20120615】
Description
假设在周末舞会上,男士们和女士们进入舞厅时,各自排成一队。跳舞开始时,依次从男队和女队的队头上各出一人配成舞伴。规定每个舞曲只能有一对跳舞者。若两队初始人数不相同,则较长的那一队中未配对者等待下一轮舞曲。现要求写一个程序,模拟上述舞伴配对问题。
Format
Input
第一行男士人数 m 和女士人数 n (m≤1000,n≤1000)
第二行舞曲的数目 k (k≤1000)。
Output
共 k 行,每行两个数,表示配对舞伴的序号,男士在前,女士在后。
Samples
输入数据 1
2 4
6
输出数据 1
1 1
2 2
1 3
2 4
1 1
2 2
Limitation
1s, 1024KiB for each test case.
题解:
用队列解决,先初始化两个队伍的队首和队尾,然后循环输出队首并使整个往后移动一位。就这么简单?就这么简单。
程序:
#include<iostream>
using namespace std;
const int N = 5000;
int n,m,k,qa[N],qb[N],fa,fb,ra,rb;
int main() {
cin>>m>>n>>k;
for(int i=1;i<=m;i++)
qa[ra++]=i;
for(int i=1;i<=n;i++)
qb[rb++]=i;
while(k--){
cout<<qa[fa]<<" "<<qb[fb]<<"\n";
qa[ra]=qa[fa];
qb[rb]=qb[fb];
fa++,fb++;
ra++,rb++;
}
return 0;
}边栏推荐
- The Go Programming Language (Introduction)
- 为何越来越多人选择进入软件测试行业?深度剖析软件测试的优势...
- The role of @Async annotation and how to implement asynchronous listening mechanism
- Go 编程语言(简介)
- 【SSR服务端渲染+CSR客户端渲染+post请求+get请求+总结】
- CS8416国产替代DP8416 数字音频接收器
- 【手撕AHB-APB Bridge】~ AMBA总线 之 AHB
- Service Mesh落地路径
- 【内存操作函数内功修炼】memcpy + memmove + memcmp + memset(四)
- 自从新来了个字节20K出来的,就见识到了什么是天花板
猜你喜欢

一点点读懂thermal(一)

NebulaGraph v3.2.0 Release Note,对查询最短路径的性能等多处优化

【游戏建模模型制作全流程】在ZBrush中雕刻恶魔城男性角色模型

Ab3d.PowerToys and Ab3d.DXEngine Crack

Literature reading ten - Detect Rumors on Twitter by Promoting Information Campaigns with Generative Adversarial Learn
![[Cultivation of internal skills of string functions] strcpy + strcat + strcmp (1)](/img/b6/5a1c8b675dc7f67f359c25908403e1.png)
[Cultivation of internal skills of string functions] strcpy + strcat + strcmp (1)

【3D建模制作技巧分享】Maya模型如何导入zbrush

逆序对的数量

js中小数四则运算精度问题原因及解决办法

App测试和Web测试的区别
随机推荐
golang打开文件和读写文件
【3D建模制作技巧分享】ZBrush纹理贴图怎么导入
【手撕AHB-APB Bridge】~ AMBA总线 之 AHB
被领导拒绝涨薪申请,跳槽后怒涨9.5K,这是我的心路历程
3年,从3K涨薪到20k?真是麻雀啄了牛屁股 — 雀食牛逼呀
temp7777
特征工程资料汇总
测试技术:关于上下文驱动测试的总结
应用联合、体系化推进。集团型化工企业数字化转型路径
The role of @Async annotation and how to implement asynchronous listening mechanism
uniapp horizontal tab (horizontal scrolling navigation bar) effect demo (organization)
typeScript-闭包函数的使用
【游戏建模模型制作全流程】使用ZBrush制作骷髅王
从“草原牛”到“数字牛”:蒙牛的数字化转型之道
对“为什么一些程序员很傲慢”的解读
I was rejected by the leader for a salary increase, and my anger rose by 9.5K after switching jobs. This is my mental journey
自从新来了个字节20K出来的,就见识到了什么是天花板
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
SRv6网络的安全解决方案
一点点读懂Thremal(二)