[AGC006B] Median Pyramid Easy(题解)
Withered_sjtu · · 题解
一道挺有意思的构造题
其实有很多种构造方法,这里介绍一种比较好想的方法。
我们想让 (有点难看)
这里我们可以证明一下
若
若
所以
同理
若
若
所以
综上,无论
所以我们写程序的时候只用将
对于无法构造的情况我们只需判断
完整代码
#include <cstdio>
int a[200005], tot = 1;
int main() {
int n, x;
scanf("%d %d", &n, &x);
if (x == 1 || x == 2 * n - 1) {
printf("No");
return 0;
}
printf("Yes\n");
a[n - 1] = x - 1, a[n] = x, a[n + 1] = x + 1;
for (int i = 1; i <= n - 2;) {
if (tot == x - 1 || tot == x || tot == x + 1) tot++;
else a[i] = tot, tot++, i++;
}
for (int i = n + 2; i <= 2 * n - 1;) {
if (tot == x - 1 || tot == x || tot == x + 1) tot++;
else a[i] = tot, tot++, i++;
}
for (int i = 1; i <= 2 * n - 1; i++) {
printf("%d\n", a[i]);
}
return 0;
}