码迷,mamicode.com
首页 > 其他好文 > 详细

round robin schedule(循环日程表)

时间:2017-09-22 22:37:40      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:math.h   str   sch   fine   schedule   pac   fse   double   iostream   

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;

}

round robin schedule(循环日程表)

标签:math.h   str   sch   fine   schedule   pac   fse   double   iostream   

原文地址:http://www.cnblogs.com/1915884031A-qqcom/p/7577183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!