当前位置:网站首页>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
边栏推荐
- 六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
- 【js】-【字符串-应用】- 学习笔记
- Huawei machine learning service speech recognition function enables applications to paint "sound" and color
- Fibonacci
- The dplyr package select function of R language moves the specified data column in the dataframe data to the first column (the first column) in the dataframe data column
- libnum库简单使用(进制字符串转换)
- 去处电脑桌面小箭头
- Tomorrow is the PMP Exam (June 25). Have you understood all this?
- Binary lookup array subscript
- Gocolly manual
猜你喜欢
2021-2022 China's financial digitalization "new" insight Industry Research Report
企业数据防泄露解决方案分享
Detailed explanation of online group chat and dating platform project (servlet implementation)
SimpleDateFormat 格式化和解析日期的具体类
当初吃土建起来的“中台”,现在为啥不香了?
7-6 铺设油井管道
Why is it that the "Zhongtai" that was originally eaten by civil engineering is no longer fragrant?
[JS] - [array, stack, queue, linked list basics] - Notes
安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX
【js】-【字符串-应用】- 学习笔记
随机推荐
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
基于三维GIS开发的水电工程建设方案
Laravel pagoda security configuration
Use of types, values, namespaces, combinations, etc. in typescript
二分查找数组下标
企业数据防泄露解决方案分享
Still using simpledateformat for time formatting? Be careful of project collapse
【js】-【栈、队-应用】-学习笔记
Why is it that the "Zhongtai" that was originally eaten by civil engineering is no longer fragrant?
7-3 maximum sub segment and
[JS] - [stack, team - application] - learning notes
Simple use of libnum Library (hexadecimal string conversion)
安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX
Yyds dry goods counting uses xshell to implement agent function
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses exp function and coef function to obtain the corresponding odds rat
libnum库简单使用(进制字符串转换)
Redis source code analysis skip list
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
Pseudo original intelligent rewriting API Baidu - good collection
Laravel authentication module auth