CiscoOA #20
Find Last Cell
估计中等可在线判题
考点(AI 标注)模拟/实现原地数组
Starting from the top-left corner, traverse the matrix one cell at a time in a counterclockwise spiral going down, right, up, then left. You land on the starting cell, and after that you skip one path cell before each landing; the count continues through turns, and the parity is never reset. Output the value of the last cell you land on.
输入格式
The input is N M followed by N lines of M integers each. The original wording of N/M as rows and columns contains a typo; this site specifies N rows and M columns. The original had no numeric bounds; this site adds 1≤N,M≤1000 and elements in −10^9..10^9.
输出格式
Output a single integer, the answer.
样例 1
输入:
3 3
29 8 37
15 41 3
1 10 14
输出:
41
样例 2
输入:
2 2
1 2
3 4
输出:
4
样例 3
输入:
1 4
9 8 7 6
输出:
7
样例说明
The outputs of the three public examples are, in order: 41; 4; 7. Verified by independent enumeration or direct simulation.