#CF 723 A
链接: link.
题意:给定一个n,之后输入2n个数通过交换2n个数的位置形成的环(相当于首尾相接)满足任意x a[x] != (a[x - 1] + a[x + 1]) / 2(不下取整).
题解:
首先对于这种构造题,找到关键点,直接看能否凑出反例特例。
任意 a[i] 若不成立则 相当于 a[i - 1] = a[i] - x , a[i + 1] = a[i] + x,可以看出a[i]的左右一定是一个比他大一个比他小,所以当左右都比它小,或者都比它大的时候就不成立了。
由此可以想到sort一下从中间分开,左半边放一下,右半边放一下,就满足小大小的结构了。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <stack>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const int N = 100010, M = 1100, INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
int n, m, x, y, k, cnt, t;
int a[N];
int main() {
cin >> t;
while (t --) {
int x;
cin >> x;
n = 2 * x;
for (int i = 0; i < n; i ++ ) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n / 2; i ++ ) cout << a[i] << ' ' << a[i + x] << ' ';
cout << endl;
}
return 0;
}