405393: GYM101933 G Game Scheduling

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Game Schedulingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

In a tournament with $$$m$$$ teams, each team consisting of $$$n$$$ players, construct a playing schedule so that each player is paired up against all players in all teams except their own. That is, each player should play $$$(m-1) \cdot n$$$ games.

The playing schedule should be divided into rounds. A player can play at most one game per round. If a player does not play a game in a round, that player is said to have a bye in that round.

Your task is to write a program that constructs a playing schedule so that no player has a bye in more than $$$1$$$ round. In other words, the total number of rounds in the playing schedule should be no more than $$$(m-1) \cdot n + 1$$$.

The order of the rounds and games, and who is home and away in a game, does not matter.

Input

The input consists of a single line with two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 25$$$, $$$2 \le m \le 25$$$, $$$n \cdot m \le 100$$$), the number of players in a team and the total number of teams, respectively.

Output

Output one line per round in the playing schedule. Each line should contain a space separated list of games. A game is in the format "<player>-<player>". The players in the first team are denoted as $$$\texttt{A}1, \texttt{A}2, ..., \texttt{A}n$$$; the second team $$$\texttt{B}1, \texttt{B}2, \ldots \texttt{B}n$$$ and so on.

ExamplesInput
3 2
Output
A1-B3 A2-B2 A3-B1 
A1-B1 A2-B3 A3-B2
A1-B2 A2-B1 A3-B3
Input
2 3
Output
A1-C2 A2-B1 B2-C1 
A2-C2 B1-C1
A1-B2 A2-C1 B1-C2
A1-C1 B2-C2
A1-B1 A2-B2
Input
1 5
Output
A1-D1 C1-E1 
A1-C1 B1-E1
A1-E1 B1-D1
B1-C1 D1-E1
A1-B1 C1-D1

加入题单

算法标签: