Easy Construction
题意:
求一个1−n的排列p,对于每个 i(i属于1−n),该排列中存在长度为 i 的连续的子序列,它的和对n取模后为k
题解:
代码:
///Easy Construction
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int n, k;
int main()
{
cin >> n >> k;
if (k != n * (n + 1) / 2 % n) { cout << -1 << endl; return 0; } //无解
if (k == 0) {//n为奇数
cout << n << ' ';
for (int i = 1; i <= n / 2; i++)
cout << i << ' ' << n - i << ' ';
cout << endl;
}
else {
cout << n << ' ' << n / 2 << ' '; //n为偶数
for (int i = 1; i < n / 2; i++)
cout << i << ' ' << n - i << ' ';
cout << endl;
}
return 0;
}