笔者的直觉告诉自己,构造一个单峰的排列即可,但没想到任何排列都满足情况。
时间复杂度 \(\mathcal O()\)
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int cnt = 1;
vector<int> ans;
for (; cnt <= n; cnt += 2) ans.push_back(cnt);
cnt -= 2;
if (cnt + 1 == n)
++cnt;
else
--cnt;
for (; cnt >= 1; cnt -= 2) ans.push_back(cnt);
for (auto i : ans) printf("%d ", i);
puts("");
}
return 0;
}
Codeforces Round #663 (Div. 2) 解题报告
原文:https://www.cnblogs.com/chhokmah/p/13498959.html