Google face question analysis: N team competition, numbered for 0,1,2 .... N-1

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.