VisaOA #14
Arrange Squares by Missing Values
估计简单可在线判题
考点(AI 标注)模拟/实现原地数组
You are given a 4×4n grid divided into n side-by-side 4×4 squares. Each square contains every value in 1..16 except one, and the missing cell is marked -1. Find the missing value by subtracting the sum of the other 15 cells from 136, then arrange the whole squares from left to right in ascending order of missing value. If missing values are equal, this site adds that the squares keep their original left-to-right order (stable).
输入格式
The first line contains n (1≤n≤10000, site-added), followed by 4 lines of 4n numbers each. Each 4×4 square must contain exactly -1 and the other 15 distinct values from 1..16.
输出格式
Output the rearranged 4-row grid.
样例 1
输入:
2
-1 1 2 3 1 2 3 4
4 5 6 7 5 6 8 9
8 9 10 11 10 11 12 13
13 14 15 16 14 15 16 -1
输出:
1 2 3 4 12 1 2 3
5 6 8 9 4 5 6 7
10 11 12 13 8 9 10 11
14 15 16 7 13 14 15 16
样例 2
输入:
1
1 2 3 5
6 -1 7 8
9 10 11 12
13 14 15 16
输出:
1 2 3 5
6 4 7 8
9 10 11 12
13 14 15 16
样例 3
输入:
3
1 2 -1 3 1 2 3 4 1 2 4 5
4 5 6 8 5 6 8 9 6 7 8 9
9 10 11 12 -1 10 11 12 10 11 12 13
13 14 15 16 13 14 15 16 14 15 -1 16
输出:
1 2 4 5 1 2 7 3 1 2 3 4
6 7 8 9 4 5 6 8 5 6 8 9
10 11 12 13 9 10 11 12 7 10 11 12
14 15 3 16 13 14 15 16 13 14 15 16