-
Notifications
You must be signed in to change notification settings - Fork 0
/
roundrobin_scheduling.cpp
60 lines (53 loc) · 1.37 KB
/
roundrobin_scheduling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* =====================================================================================
*
* Filename: roundrobin_scheduling.cpp
*
* Description:
*
* Version: 1.0
* Created: 06/26/14 09:37:04
* Revision: none
* Compiler: gcc
*
* Author: (),
* Company: NDSL UESTC
*
* =====================================================================================
*/
#include <iostream>
#include <vector>
using namespace std;
#define MAXN 512
vector<vector<short> > schedule(MAXN, vector<short>(MAXN, 0) );
void dc(const int k) {
int i, j, t;
int n, n2;
n = 2;
schedule[0][0] = 1; schedule[0][1] = 2;
schedule[1][0] = 2; schedule[1][1] = 1;
for (t = 1; t < k; t++, n *= 2) {
n2 = n * 2;
for (i = n; i < n2; ++i)
for (j = 0; j < n; ++j)
schedule[i][j] = schedule[i-n][j] + n;
for (i = 0; i < n; ++i)
for (j = n; j < n2; ++j)
schedule[i][j] = schedule[i + n][j - n];
for (i = n; i < n2; ++i)
for (j = n; j < n2; ++j)
schedule[i][j] = schedule[i - n][j-n];
}
}
int main() {
int k, N;
int i, j;
cin >> k;
N = 1 << k;
dc(k);
for (i = 0; i < N; ++i) {
for (j = 1; j < N; ++j)
cout << schedule[i][j] << " ";
cout << endl;
}
}