TopCoder problem "MitchellMovement" used in TCO04 Round 4 (Division I Level One)



Problem Statement

    

In duplicate bridge, when cards are shuffled and dealt, they are placed in boards so that different teams can play exactly the same deals, greatly reducing the role of luck in the game. The boards and teams move around in an intricate pattern called a movement, designed in such a way that teams never play the same board twice. The Mitchell movement is one of the most commonly used movements.

In a Mitchell movement for N tables, there are N North-South teams, numbered from 1 to N, and N East-West teams, also numbered from 1 to N. Each North-South team K sits at table K, and does not move for the duration of the tournament. Each East-West team K starts at table K and moves to the next higher table at the conclusion of each round, with the East-West team at table N moving to table 1.

In each round, three boards are played at each table. The boards are numbered from 1 to 3N, and are initially placed in numerical order, starting at table 1. In other words, boards 1-3 start at table 1, boards 4-6 start at table 2, and so on. At the conclusion of each round, each board is moved to the next lower table, with the boards at table 1 being moved to table N.

There is one complication to this simple story. When there are an even number of tables, the East-West teams would start seeing boards they've already played halfway through the tournament. To prevent this, a skip is called after each team has played half the boards. When the skip is called, each East-West teams moves up two tables instead of one table, wrapping around from the high-numbered tables to the low-numbered tables as necessary. The tournament is then halted when the East-West teams return to their original tables, which means that each team will have played all but three of the boards. Keep in mind that skips are not called when there are an odd number of tables.

Given the number of tables N, a round number, and a board number, you must determine which North-South team and which East-West team play that board in that round. Return the team numbers in a int[] with two elements, first the North-South team number and then the East-West team number. Note that the rounds are numbered starting with 1.

 

Definition

    
Class:MitchellMovement
Method:teams
Parameters:int, int, int
Returns:int[]
Method signature:int[] teams(int N, int round, int board)
(be sure your method is public)
    
 

Constraints

-N is between 7 and 20, inclusive.
-round is between 1 and N, inclusive, if N is odd, and between 1 and N-1, inclusive, if N is even.
-board is between 1 and 3N, inclusive.
 

Examples

0)
    
8
1
1
Returns: { 1,  1 }
In round 1, board 1 is played at table 1 by North-South team 1 and East-West team 1.
1)
    
7
2
8
Returns: { 2,  1 }
Board 8 starts at table 3. In round 2, it moves to table 2, where it is played by North-South team 2 and East-West team 1.
2)
    
20
11
35
Returns: { 2,  11 }
Don't forget the skip!
3)
    
19
19
19
Returns: { 8,  9 }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2966

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5881&pm=2966

Writer:

vorthys

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Simulation