Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
a_1, a_2, ..., a_n我必须制作一个满足的非连续整数序列
a_1, a_2, ..., a_n
{a_1, a_2, ..., a_n} ∈ [1, n]
|a_i - a_(i-1)| > 1
怎么做?感谢您的提示或帮助。谢谢 :)
当元素少于4个时,这是不可能的。
当有 4 个或更多元素时,我们可以这样构造序列:
如果 n 是偶数:
[n-1, n-3, ... , 1, n, n-2, ..., 2]
如果 n 是奇数:
[n, n-2, ..., 1, n-1, n-3, ..., 2]
现在 n 等于或大于 4,|1-n| = |n-1| >= 3, |1-(n-1)| = |1-n+1| = |n| >= 4,序列满足约束。