cf#758-B. Build the Permutation(补题)

cf#758-B. Build the Permutation(补题),第1张

cf#758-B. Build the Permutation(补题)
#include

using namespace std;

const int N = 1e5 + 10;
int n;
int f[N];
int main () {
	int t;
	cin >> t;
	while (t --) {
		int a, b, n;
		cin >> n >> a >> b;
		if (abs(a - b) > 1 || a + b > n - 2) puts("-1");
		else {
			int x = 1, y = n;
			int z = (a > b);
			for (int i = 1; i<= n; i ++) {
				if (z) f[i] = x ++;
				else f[i] = y --;
				if (i <= a + b) z ^= 1;
			}
			for (int i= 1; i<= n; i ++) cout << f[i] << " ";
			puts("");
		}
	}
	return 0;
}

[Problem - B - Codeforces](https://codeforces.com/contest/1608/problem/B) 每一个波峰都会产生一个波谷,反之亦然。 对于波峰和波谷,谁大谁先产生。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5670401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存