当前位置:网站首页>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 .
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
边栏推荐
猜你喜欢

一文理解OpenStack网络
![[basic knowledge] ~ half adder & full adder](/img/06/7f1ede65dca527c8630285b587a4ba.png)
[basic knowledge] ~ half adder & full adder

Idea creation module prompt already exists

Actipro WPF Controls 2022.1.2

安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX

当初吃土建起来的“中台”,现在为啥不香了?

【js】-【数组应用】-学习笔记

Adding, deleting, querying and modifying MySQL tables

Volcano成Spark默认batch调度器
![[JS] - [array, Stack, queue, Link List basis] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, Stack, queue, Link List basis] - Notes
随机推荐
7-2 solving the stock buying problem
Idea creation module prompt already exists
Chapter VI skills related to e-learning 5 (super parameter verification)
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function, confint function and coef function to obtain the confidence
Gocolly manual
What good smart home brands in China support homekit?
Docker-mysql8-master-slave
Force deduction solution summary 515- find the maximum value in each tree row
Notes for laravel model
【js】-【字符串-应用】- 学习笔记
jar中没有主清单属性
Pseudo original intelligent rewriting API Baidu - good collection
Concurrent shared model management
Laravel creates a service layer
如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
Simple use of libnum Library (hexadecimal string conversion)
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
Helix distance of point