Topic:
N team competitions, numbered for 0,1,2 .... N-1, known for their strength-contrast relationships, stored in a two-dimensional array w[n][n], W[i][j] 's value represents a stronger branch of the team numbered i,j. So W[i][j]=i or J, now given their order of appearances and stored in the array order[n], such as order[n] = {4,3,5,8,1 ...}, then the first round is 4 to 3, 5 to 8. .......
Winners are promoted, losers are eliminated, elimination of the same round of all ranks no longer subdivided, that can be arbitrarily row, the next round by the last round of the winners in order, then 22 ratio, such as may be 4 to 5, until the first programming implementation, given a two-dimensional array w, one-dimensional array orders and An array result[n] for outputting the game rank, to find result.
Analysis:
This is not difficult, just keep traversing the order table until you find all the results.
Implemented as follows:
#include <iostream> using namespace std;
#define N 5 void GetResult (int (*w) [n], int* order, int* result) {int i = 0;
int k = 1;
int j = N-1;
while (1) {i = 0;
if (i + K > N-1) {result[j] = order[0];
Break while (i + K <= N-1) {int II = O
Rder[i];
int JJ = Order[i+k];
if (W[II][JJ] = = II) result[j--] = JJ;
else {Result[j] = II;
Order[i]= Order[i+k];
ORDER[I+K] = Result[j];
J--;
} i = i + 2*k;
} k *= 2;
int main () {int a[5][5] = {{0,1,2,3,4},{1,1,2,3,4},{2,2,2,3,4},{3,3,3,3,4},{4,4,4,4,4}};
int order[5] = {4,3,1,2,0};
int result[5];
GetResult (A, order, result);
int i = 0;
cout << "result order:";
while (I < 5) {cout << result[i++] << ",";
} cout << Endl; }
The output results are:
Result order:4,0,2,1,3,
Author: csdn Blog hhh3h
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/