A. Beautiful Matrix
- 即相当于求1到中心位置((2,2))的曼哈顿距离。
B. Squares
- 排序,取倒数第(k)个即可。
C. Circle of Numbers
- 固定(a_1=1),在与1配对的数中枚举(a_2,a_3),若(a_2,a_3)配对,则在(a_2)中枚举(a_n、a_4),此时,与(a_3)配对的数只剩一个,推出来后,与(a_4)配对的数也只剩一个,以此类推。
- 最后需要特判的位置为1、n、n-1、n-2,并且1-n的每个数只能出现一次,若都满足说明找到了可行解。
D. Cycle in Graph
- 从任意点(设为(u))开始深搜,当走到第(k+1)个点时(设为(v)),此时若(u、v)有连边,说明找到一种方案;否则由于(v)至少有k个点相连边,说明(v)可以继续扩展,直到遇到两个点深度差大于(k)。
E. Rhombus
- (s(i,j))表示二维前缀和;
- (s1(i,j)=s1(i-1,j+1)+s(i,j))
- (s2(i,j)=s2(i-1,j-1)+s(i,j))
- 根据(s1(i,j)和s2(i,j))可(O(1))计算(f(x,y))。