Chef and squares
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has finished his freshman year in college. As a present, his parents gave him a new problem to solve:
Chef has to fill a K x K square grid of integers in a certain way. Let us say that such a grid is valid if:
- Each cell contains an integer from 1 and K (inclusive).
- No integer appears twice in the same row or the same column.
Let F(K) be maximum possible distance between the center of the square and the closest cell that contains 1, among all possible squares with the side length K.
Here, we use the following notions:
- The distance between cell (x, y) and (i, j) is equal to |x-i|+|y-j|.
- The center of a K x K square is cell ((K+1)/2, (K+1)/2) for odd K.
The first line of input contains a single integer T denoting the number of test cases.
Each test case consists of a single line containing a single odd integer K.
OutputFor each test case, print K lines each consisting of K space separated integers giving some square grid where the distance from the center of the grid to the nearest 1 is exactly F(K). If there's more than 1 possible answer output any of them.
- Ki is odd.
- 1 ≤ T ≤ 50
- 1 ≤ Ki≤ 5
- 1 ≤ T ≤ 10
- 1 ≤ Ki < 400
Input: 2 1 3 Output: 1 3 2 1 1 3 2 2 1 3
|Tags||basic-prog, fiter, nov16, simple|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions