当前位置:网站首页>7-8 循环日程安排问题
7-8 循环日程安排问题
2022-06-24 19:43:00 【白—】
7-8 循环日程安排问题
用分治法求解循环日程安排问题。设有n=2 k个选手要进行网球循环赛,要求设计一个满足以下要求的比赛日程表:
(1)每个选手必须与其他n-1个选手各赛一次。
(2)每个选手一天只能赛一次。
(3)循环赛在n-1天之内结束。
输入样例:
输入K值。
3
输出样例:
输出比赛日程表。
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
代码:
#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三
边栏推荐
- websocket长链接压测
- laravel 消息队列
- Super detailed cookie addition, deletion, modification and query
- Construction equipment [6]
- laravel model 注意事项
- Jetpack Compose 最新进展
- Whereabouts computer desktop small arrow
- 【基础知识】~ 半加器 & 全加器
- [JS] - [tree] - learning notes
- Chapter VI skills related to e-learning 5 (super parameter verification)
猜你喜欢
随机推荐
【js】-【數組、棧、隊列、鏈錶基礎】-筆記
From client to server
Construction equipment [4]
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
376. 機器任務
伪原创智能改写api百度-收录良好
Force deduction solution summary 515- find the maximum value in each tree row
Laravel add helper file
QT to place the form in the lower right corner of the desktop
[JS] - [tree] - learning notes
docker-mysql8-主从
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
Construction equipment [5]
376. Tâches mécaniques
Installation and deployment of ganglia
去处电脑桌面小箭头
01_ Getting started with the spingboot framework
laravel model 注意事项
Record the range of data that MySQL update will lock



![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)





