Duties

Description

School principal introduced a new system of duties to maintain order in all classrooms. Each student is assigned one classroom he is responsible for. Each day two students responsible for different classrooms should be on duty. These students should water the flowers in their classrooms and ensure that the highlighters in computer classrooms are not dry. The principal wants you to make a plan of the duties for the first  m days of study. Each of the students should be on duty at least once during these days. You are to determine for each student the classroom he will be responsible for and the days this student will be on duty. Of course, each classroom should be assigned to at least one student. In addition to that, the principal requires that no pair of students should be on duty twice. To make your task easier, the principal allows you to distribute the duties unevenly — the students who misbehave will have more duties than those who are diligent.

Input

The first line contains three space-separated integers:  n — the number of students in the school,  k — the number of classrooms, and  m — the number of days in the required plan of duties. These numbers satisfy the constraint  2 ≤  k ≤  n ≤ 100 . You may assume that there is at least one correct plan of the duties for given  nk and  m.

Output

Let the students be numbered from 1 to  n, and the classrooms numbered from 1 to  k. Output the assignments of the students to the classrooms on the first  n lines:  i-th line should contain the number of classroom  i-th student is responsible for. The next  m lines should contain the pairs of numbers of students who will be on duty on each of  m days. Remember that these pairs should be unique, and the students who are responsible for the same classroom can't be paired.

Sample Input

input output
5 3 4
1
2
1
2
3
1 2
3 4
3 5
4 5
4 2 4
1
2
1
2
1 2
3 4
1 4
2 3


本题有多组结果,而只要能找出一种就可以!而测试样例就不用多看了!!


代码:

#include<stdio.h>
#include<string.h>
#define Max 105
int main(){
    int n,k,m;
    int i,j;
    int stu[Max],cla[Max];
    int mark[Max][Max];
    memset(mark,0,sizeof(mark));
    scanf("%d%d%d",&n,&k,&m);
    for(i=1,j=0;i<=n;i++,j++){
        j%=k;
        stu[i]=j%k+1;
    }
    for(i=1;i<=n;i++)
        printf("%d\n",stu[i]);
    int num=0;
    for(i=1;i<n;i+=2){
        printf("%d %d\n",i,i+1);
        mark[i][i+1]=1;
        mark[i+1][i]=1;
        num++;
        if(num==m)
            break;
    }
    //num=0;
    int mark1=0;
    if(n%2==1){
        for(i=1;i<n;i++)
            if(mark[i][n]==0 && stu[i]!=stu[j]){
                mark[i][n]=1;
                mark[n][i]=1;
                 printf("%d %d\n",i,n);
                 num++;
                 break;
            }
    }
    //printf("num=%d\n",num);
    if(num<m){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                if(i==j)
                    continue;
                if(mark[i][j]==0 && stu[i]!=stu[j]){
                    mark[i][j]=1;
                    mark[j][i]=1;
                    printf("%d %d\n",i,j);
                    num++;
                }
                if(num==m){
                    mark1=1;
                    break;
                }
            }
            if(mark1)
                break;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值