round robin schedule(循环日程表)

the source of the article:https://github.com/Fibird/Round-robin-schedule

 

 

#include <iostream>
#include <math.h>

#define N 3

using namespace std;

int main()
{
int sche = pow(2.0, N); //the number of athlete
int **arr = new int*[sche];
int bw = 1;
for(int i=0; i<sche; i++)
{
arr[i] = new int[sche];
}
int bid; //the id of block
int c_offset, r_offset;

//init line 1 with 1 to 8
for(int i=0; i<sche; i++)
arr[0][i] = i + 1;

for(int j=0; j<N; j++)
{
for(int r=0; r<bw; r++)
{
for(int c=0; c<sche; c++)
{
bid = (c + bw) / bw;
c_offset = pow(-1.0, bid+1) * bw; //move to right or move to left bw location
r_offset = bw;
arr[r + r_offset][c + c_offset] = arr[r][c];
}
}
bw = bw * 2; //every loop the problem will double
}

// outputs the schedule of the round robin
cout << "N/D";
for(int i=1; i<sche; i++)
cout << "\t" << i;
cout << endl;
for(int i=0; i<sche; i++)
{
cout << arr[i][0];
for(int j=1; j<sche; j++)
{
cout << "\t" << arr[i][j];
}
cout << endl;
}

//free memory
for(int i=0; i<sche; i++)
delete arr[i];
delete arr;
return 0;

}

转载于:https://www.cnblogs.com/1915884031A-qqcom/p/7577183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值