游客 Signup | Login
中文 | En

3601 - 周末舞会

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

<div>
</div>

Input

输入3个整数m,n,k,分别表示男士人数、女士人数、 几轮舞曲。

Output


输出各轮舞曲的配对方案。

<br />

<br />

Examples

Input

2 4 6

Output

1 1
2 2
1 3
2 4
1 1
2 2

Solution C

#include<stdio.h>

int main(){
	int m,n,k,i,j;
	scanf("%d%d%d",&m,&n,&k);
	i=j=1;
	while(k-->0){
		printf("%d %d\n",i++,j++);
		if(i>m)i=1;
		if(j>n)j=1;
	}
	return 0;
}

Solution C++

#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
queue<int> q1;
queue<int> q2;
int m,n,k;
int main(){
	scanf("%d%d%d",&m,&n,&k);
	int a=0,b=0;
	for (int i=1;i<=k;i++){
		if (++a==m+1) a=1;
		if (++b==n+1) b=1;
		q1.push(a);q2.push(b);
	}
	for (int i=1;i<=k;i++){
		printf("%d %d\n",q1.front(),q2.front());
		q1.pop();q2.pop();
	}
	return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题