The divide and conquer algorithm solves the round robin problem.

Source: Internet
Author: User

The divide and conquer algorithm solves the round robin problem.
I. Basic Idea of the divide and conquer algorithm

When we solve some problems, the direct solution takes a long time or cannot be directly obtained because of the large amount of data to be processed or the complicated process. For this type of problem, we often break it down into several subproblems, find the solutions to these subproblems, and then find the appropriate method, combine them to solve the entire problem. If these subproblems are still large and difficult to solve, you can divide them into several smaller subproblems, and so on until you can solve them directly. This is the basic idea of the sub-governance strategy.

Ii. Steps for solving the problem using the divide and conquer algorithm

(1) decomposition: the problems to be solved are divided into several similar problems of small scale;
(2) solve the problem by using a simple method when the sub-problem is divided into sufficient hours;
(3) Merge sub-problems to form the solution of the original problem according to the requirements of the original problem.

Iii. application scenarios of divide and conquer Algorithms

Problems solved using the divide and conquer strategy generally have the following characteristics:
(1) the original problem can be divided into multiple subproblems. These subproblems are not the same as the original problems, but their scale is reduced. Their structures and solutions are the same or similar to those of the original problems.
(2) In the decomposition process of the original problem, recursive subproblem solving must have an ending condition. Therefore, when the subproblem after decomposition is small enough, it should be able to solve the problem directly.
(3) After solving and obtaining the solutions of each subproblem, some methods and methods should be used to merge or construct the solution of the original problem.

Iv. Round Robin schedule issues

Question: There are n = 2 ^ k teams participating in the round robin competition, and a schedule meeting the following requirements is required:
(1) Each team must compete with other n-1 teams once;
(2) Each team can only participate once a day;
(3) The Round Robin ends within n-1 days.

According to this requirement, the competition schedule is designed into a table with n rows and n columns. In row I of the table, set column j to the Team that the I team encountered on day j. 1 ≤ I ≤ n, 2 ≤ j ≤ n. The schedules of the eight teams are as follows:

  

V. Divide and conquer law to solve the Round Robin Problem
1/** 2 * Sub-division algorithm: Round Robin Schedule 3 * Subject: 2 ^ n teams, round robin, requirements: 4 * (1) each team must compete with the other n-1 teams each time. 5 * (2) each team can only participate once a day; 6 * (3) the round robin ends within n-1 days. 7 * @ author Administrator 8*9 */10 public class Dispatch {11/** 12 * Round Robin schedule 13 * @ param table round robin Schedule 14 * @ param n number of teams 15 */16 private void scheduleTable (int [] [] table, int n) {17 // only one team 18 if (n = 1) {19 table [0] [0] = 1; 20} else {21 // fill in the upper left area matrix 22 int m = n/2; 23 // recursively determine the upper left area matrix 24 scheduleTable (table, m ); // This is the 25 round robin for the m team. // fill in the upper right area matrix 26 // determine the upper right area matrix 27 for (int I = 0 based on the upper left area that has been filled; I <m; I ++) {28 for (int j = m; j <n; j ++) {29 table [I] [j] = table [I] [j-m] + m; 30} 31} 32 33 // fill in the lower left area matrix 34 // fill in the lower left area matrix 35 for (int I = m; I <n; I ++) based on the upper right area Matrix) {36 for (int j = 0; j <m; j ++) {37 table [I] [j] = table [j] [I]; 38} 39} 40 41 // fill in the lower right area matrix 42 // fill in the lower right area matrix 43 for (int I = m; I <n; I ++) based on the upper left area Matrix) {44 for (int j = m; j <n; j ++) {45 table [I] [j] = table [I-m] [j-m]; 46} 47} 48} 49} 50 51 public static void main (String [] args) {52 int n = 16; // team 53 int [] [] table = new int [n] [n]; 54 Dispatch = new dispatch (); 55 Dispatch. scheduleTable (table, n); 56 57 // print the result 58 for (int I = 0; I <table. length; I ++) {59 for (int j = 0; j <table [I]. length; j ++) {60 System. out. print (table [I] [j] + ""); 61} 62 System. out. println (); 63} 64} 65 66}
6. Test Results

 The schedule of the 16 teams for the round robin is as follows::

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 3 4 1 2 7 8 5 6 11 12 9 10 15 16 13 14 4 3 2 1 8 7 6 5 12 11 10 9 16 15 14 13 5 6 7 8 1 2 3 4 13 14 15 16 9 10 11 12 6 5 8 7 2 1 4 3 14 13 16 15 10 9 12 11 7 8 5 6 3 4 1 2 15 16 13 14 11 12 9 10 8 7 6 5 4 3 2 1 16 15 14 13 12 11 10 9 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 10 9 12 11 14 13 16 15 2 1 4 3 6 5 8 7 11 12 9 10 15 16 13 14 3 4 1 2 7 8 5 6 12 11 10 9 16 15 14 13 4 3 2 1 8 7 6 5 13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4 14 13 16 15 10 9 12 11 6 5 8 7 2 1 4 3 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 

 

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.