当前位置:网站首页>7-8 circular scheduling problem

7-8 circular scheduling problem

2022-06-24 23:31:00 White -

7-8 Circular scheduling problem

Using divide and conquer method to solve circular scheduling problem . Equipped with n=2 k A player is going to have a tennis round robin , It is required to design a competition schedule that meets the following requirements :
(1) Each player has to work with others n-1 Each contestant has a competition .
(2) Each player can only play once a day .
(3) The round robin is n-1 Within days .
 Insert picture description here
sample input :
Input K value .

3

sample output :
Output game schedule .

1 2 3 4 5 6 7 8
2 1 4 3 6 5 8 7
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
5 6 7 8 1 2 3 4
6 5 8 7 2 1 4 3
7 8 5 6 3 4 1 2
8 7 6 5 4 3 2 1

Code :

#include<stdio.h>
int n;
int a[10100];
void print()
{
    
    for(int i=1;i<=n;i++)
        printf("%d ",a[i]);
    printf("\n");
}
void schange()
{
    
    int temp;
    for(int i=1;i<=n-1;i+=2)
    {
    
        temp=a[i];
        a[i]=a[i+1];
        a[i+1]=temp;
    }
}
void bchange(int x)
{
    
    int temp;
    for(int i=1;i<=n-2*x+1;i+=2*x)
    {
    
        for(int j=i;j<i+x;j++)
        {
    
            temp=a[j];
            a[j]=a[j+x];
            a[j+x]=temp;
        }
    }
}
int main()
{
    
    scanf("%d",&n);
    n=pow(2,n);
    for(int i=1;i<=n;i++)
        a[i]=i;
    print();
    int i;
    for(i=1;i<n/2;i++)
    {
    
        if(i%2!=0)
        {
    
            schange();
            print();
        }
        else
        {
    
            schange();
            bchange(i);
            print();
        }

    }
    for(int i=1;i<=n/2;i++)
    {
    
       a[i]=n/2+i;
       a[n/2+i]=i;
    }
    print();
    for(i=1;i<n/2;i++)
    {
    
        if(i%2!=0)
        {
    
            schange();
            print();
        }
        else
        {
    
            schange();
            bchange(i);
            print();
        }

    }
    return 0;
}

202206222118 3、 ... and

原网站

版权声明
本文为[White -]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241820370470.html