Lab #4: Decrease and Conquer
Students implemented the following problems using "Decrease and Conquer" technique.
  1. Topological Sorting:
                               Input                                       Output
 Content of the "input_1.txt" file:
 - Dòng thứ 1: positve integer n represent the number of courses.
                                                                           Topology order of courses.
 - Next klines: Courses relationships.
 - End with 0.
 Example:
 5
 3 1 2 (1 and 2 need to be done before 3)
                                                                           12345
 43     (3 need to be done before 4)
 5 3 4 (3 and 4 need to be done before 5)
 0
  2. Josephus problem: Let n people stand in a circle. Starting the count with person number 1,
     we eliminate every second person until only one survivor is left. The problem is to determine the
     survivor’s number J(n).
                Input                  Output
 Content of the "input_2.txt" file:
                                       - Eliminated people (time order)
 - Positive integer n represent the
                                       - Last survivor.
 amount of people in the circle.
 Example:                              2415
 5                                     3
  3. Selection problem: Finding the k th smallest number in an array S = {s1 , s2 , ..., sn } với k ∈ [1, n]
                               Input                                 Output
 Content of the "input_3.txt" file:
 - 1st line: positive integer n represent size of the given array.
                                                                     - k th smallest number required.
 - 2nd line: n real numbers separated by a single space " ".
 - 3rd line: positive integer k
 Example:
 5
                                                                     3.3
 1.1 7.3 2.5 4.6 3.3
 3
 4. Interpolation Search: Find the value k from the given array which has n elements.
                              Input                                Output
Content of the "input_4.txt" file:
- 1st line: positive integer n represent size of the given array
- 2nd line: n real numbers sorted ascendingly. Separated by        - Position (from 0) of x.
a single space " ".
- 3rd line: Required real x number
Example:
5
                                                                   1
1.1 2.2 3.3 4.4 5.5
2.2
 • FILE SUBMISSION REGULATION
       – Only submit files with .cpp extensions: 1.cpp, 2-1.cpp, 2-2.cpp ... . Project submission
         is illegal.
       – .cpp files must be located in MSSV folder, then be compressed into MSSV.zip(.rar).
       – Source code must receive input and return output as specified for each problem. Submissions
         with wrong regulation will result in a "0" (zero).
       – Plagiarism and Cheating will result in a "0" (zero) for the entire course.
       – Contact: bhthong@fit.hcmus.edu.vn for more information.
                                                           END