Theater Seating
Time limit1sMemory limit128 MB
Assign each seat a priority by Euclidean distance to the middle of row 1, breaking ties by row then by seat number, and print rows back to front.
- Level
Easy3 of 10
- Topics
- Sorting, Math, Implementation
- Solved
- No attempts yet
Problem
A theater has seats arranged in a rectangle: an odd number of seats per row, the width (), and rows (). Within a row the seats are numbered to from left to right (as seen from the stage), and the rows are numbered to starting from the row closest to the stage. Adjacent seats in the same row are one unit apart, and this spacing equals the distance between a seat and the seat directly in front of or behind it in an adjacent row. So seat in row occupies the grid point .
Tickets are sold online with automatic seat assignment, so every seat is given a unique priority, where priority is the best. Priorities are assigned by these rules:
- The middle seat of row (the row closest to the stage), at position , gets the best priority, .
- Every other seat is ranked by its Euclidean distance to that best seat: the closer a seat is, the better (smaller) its priority.
- Among seats that are exactly the same distance away, a seat in a row closer to the stage (a smaller row number) gets the better priority.
- Among seats that are the same distance away and in the same row, the seat closer to seat number (the left-most seat) gets the better priority.
Because is unique for every seat, these rules assign a distinct priority to each of the seats. Write a program that prints the resulting priority chart for a given width and number of rows.
Input
The only line contains two space-separated integers and , where is odd, , and .
Output
Print lines. For , line contains the priorities of the seats in row , listed from seat to seat and separated by single spaces. In other words, print the rows from the back of the theater (row ) down to the front row (row ).