1332:【例2-1】周末舞会

1332:【例2-1】周末舞会

1332:【例2-1】周末舞会


时间限制: 1000 ms         内存限制: 65536 KB
提交数: 2808     通过数: 2067 

【题目描述】

假设在周末舞会上,男士们和女士们进入舞厅时,各自排成一队。跳舞开始时,依次从男队和女队的队头上各出一人配成舞伴。规定每个舞曲能有一对跳舞者。若两队初始人数不相同,则较长的那一队中未配对者等待下一轮舞曲。现要求写一个程序,模拟上述舞伴配对问题。

【输入】

第一行两队的人数;

第二行舞曲的数目。

【输出】

配对情况。

【输入样例】

4 6
7

【输出样例】

1 1
2 2
3 3
4 4
1 5
2 6
3 1


代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
int man[10000],woman[10000],t1=1,t2=1,w1,w2,k1,k,m,w;
int main()
{
    cin>>m>>w>>k;
    for(int i=1;i<=m;i++)
      man[i]=i;
    for(int i=1;i<=w;i++)
      woman[i]=i;
      
    w1=m;w2=w;
    
    while(k1<k)       //k1记录跳的舞曲数
    {
        printf("%d %d
",man[t1],woman[t2]);
        w1++;man[w1]=man[t1];t1++;            //人数可能不相等,当他们跳完之后就自觉回到队尾
        w2++;woman[w2]=woman[t2];t2++;
        k1++;
    }

    return 0;
    
}
原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/10700307.html