#P2552. Determine the Athlete's Position in the Formation
Determine the Athlete's Position in the Formation
Determine the Athlete's Position in the Formation
There are (n) athletes numbered from (1) to (n). They are arranged in one of two formation types: the continuous formation and the plum formation (梅花桩队形). Furthermore, the arrangement can be done by rows or by columns. When arranged by rows, each row has exactly (r) positions; when arranged by columns, each column has exactly (r) positions.
In the continuous formation the athletes are filled sequentially:
- Row arrangement: fill the formation row by row (left to right).
- Column arrangement: fill the formation column by column (top to bottom).
- For row arrangement: In odd-numbered rows the athletes are placed in the odd-numbered columns (i.e. columns \(1,3,5,\dots\)) while in even-numbered rows they are placed in the even-numbered columns (i.e. columns \(2,4,6,\dots\)). The number of available positions in an odd row is \(\lceil r/2 \rceil\) and in an even row is \(\lfloor r/2 \rfloor\).
- For column arrangement: In odd-numbered columns the athletes are placed in the odd-numbered rows and in even-numbered columns they are placed in the even-numbered rows. The number of available positions in an odd column is \(\lceil r/2 \rceil\) and in an even column is \(\lfloor r/2 \rfloor\).
- An integer indicating the formation type:
1
for continuous formation and2
for plum formation. - A character indicating the arrangement order:
R
if arranged by rows andC
if arranged by columns.
inputFormat
The input consists of two lines:
The first line contains two tokens separated by space:
- An integer (
1
for continuous formation,2
for plum formation). - A character (
R
for row arrangement,C
for column arrangement).
The second line contains three space-separated integers:
- (n): total number of athletes.
- (r): number of positions in each row (or column).
- (m): the athlete number whose position is to be determined. It is guaranteed that (1 \le m \le n).
outputFormat
Output two integers separated by a space: the row number and the column number where athlete (m) is located.
sample
1 R
16 6 16
3 4