当前位置:网站首页>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
边栏推荐
- UNION ALL UNION FULL JOIN
- Laravel scheduled task
- go 语言指针,值引用和指针引用
- Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
- Still using simpledateformat for time formatting? Be careful of project collapse
- throttle-debounce.js:一个小型的防抖节流函数库
- Tomorrow is the PMP Exam (June 25). Have you understood all this?
- 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
- [introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
- Laravel pagoda security configuration
猜你喜欢

Installation and deployment of ganglia

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

RT thread uses RT kprintf

宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权

idea创建模块提示已存在

Huawei machine learning service speech recognition function enables applications to paint "sound" and color
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes

Idea creation module prompt already exists

#22Map介绍与API

MySQL 表的增删查改
随机推荐
Installation and deployment of ganglia
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
Use of types, values, namespaces, combinations, etc. in typescript
7-9 寻宝路线
websocket学习
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
【js】-【数组、栈、队列、链表基础】-笔记
Redis source code analysis skip list
Spark's wide dependence and narrow dependence yyds dry goods inventory
7-5 最大子矩阵和问题
sql -CONVERT函数
7-2 后序+中序序列构造二叉树
Bubble sort
Laravel creates a service layer
六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
Use of laravel verifier
Morris遍历
378. 骑士放置
一文理解OpenStack网络