Solving the round robin problem by divide-and-conquer algorithm

Source: Internet
Author: User

I. Basic idea of divide and conquer algorithm

When we solve some problems, because these problems to deal with a considerable amount of data, or the process is quite complex, so that the direct solution in time is quite long, or simply can not be directly obtained. For this kind of problem, we often first decompose it into several sub-problems, find out the solution of these sub-problems, then find the appropriate method, combine them into the solution of the whole problem. If these sub-problems are larger, difficult to solve, they can be divided into several smaller sub-problems, and so on, until the solution can be directly solved. This is the basic idea of the divide-and-conquer strategy.

two. Steps to solve problems of divide and conquer algorithm

(1) Decomposition, the problem to be solved divided into a number of small-scale similar problems;
(2) solving, when sub-problem is divided into enough hours, with a relatively simple method to solve;
(3) Merging, according to the requirements of the original problem, the solution of sub-problem is composed of layers to form the solution of the original problem.

three. Application scenarios for divide-and-conquer algorithms

The problems solved by using the divide-and-conquer strategy generally have the following characteristics:
(1) The original problem can be decomposed into multiple sub-problems these sub-problems are compared with the original problem, but the scale of the problem is reduced, and the structure and solution method are the same or similar to the original problem.
(2) The original problem in the decomposition process, the recursive solution of the sub-problem due to recursion must have a termination condition, so when the decomposition of sub-problem size enough, should be able to directly solve.
(3) after solving and obtaining the solution of each sub-problem, we should be able to merge or construct the solution of the original problem in some way or by method.

four. Round robin Calendar issues

Question: There is a n=2^k team to participate in the round robin, to design a meeting to meet the following requirements schedule:
(1) Each team must match with other n-1 teams once;
(2) Each team can only compete once a day;
(3) The round robin ends within n-1 days.

The tournament schedule is designed as a table with n rows and n columns, as required. In line I of the table, column J is filled with the team that I met on J Day for the first team. Which 1≤i≤n,2≤j≤n. 8 teams ' game schedules such as:

  

five. Divide-and-conquer method to solve the round robin problem
1 /**2 * Divide and conquer algorithm: round robin calendar3 * Title: 2^n team, for the round robin, the requirements are as follows:4 * (1) Each team must match with other n-1 teams once;5 * (2) Each team can only compete once a day;6 * (3) The round robin ends within n-1 days. 7  * @authorAdministrator8  *9  */Ten  Public classDispatch { One     /** A * Round robin Calendar Schedule -      * @paramtable round robin Calendar -      * @paramn the number of teams the      */ -     Private voidScheduletable (int[] table,intN) { -         //There's only one team . -         if(n==1) { +Table[0][0]=1; -}Else { +             //fills the upper left area matrix A             intM=n/2; at             //recursive determination of the upper left area matrix -Scheduletable (table, m);//even the M-teams are playing round robin -             //fills the upper right area matrix -             //determines the upper-right area matrix based on the upper-left area that is already populated -              for(inti=0;i<m;i++) { -                  for(intj=m;j<n;j++) { intable[i][j]=table[i][j-m]+m; -                 } to             } +              -             //fill the lower left area matrix the             //fills the lower left area matrix according to the upper right area matrix *              for(inti=m;i<n;i++) { $                  for(intj=0;j<m;j++) {Panax Notoginsengtable[i][j]=Table[j][i]; -                 } the             } +              A             //fill the lower right area matrix the             //fills the lower-right area matrix based on the upper-left area matrix +              for(inti=m;i<n;i++) { -                  for(intj=m;j<n;j++) { $table[i][j]=table[i-m][j-m]; $                 } -             } -         } the     } - Wuyi      Public Static voidMain (string[] args) { the         intn=16;//Team -         int[] table=New int[n][n]; WuDispatch dispatch=NewDispatch (); - dispatch.scheduletable (table, n); About          $         //Print Results -          for(inti=0;i<table.length;i++) { -              for(intj=0;j<table[i].length;j++) { -System.out.print (table[i][j]+ ""); A             } + System.out.println (); the         } -     } $  the}
Six. Test results

 The 16-team round robin schedule is as follows :

Solving the round robin problem by divide-and-conquer algorithm

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.