题目大意
给你一个有
(来源:https://blog.csdn.net/zuzhiang/article/details/78575126)
题解
害怕,乱搞了一发,然后就 A 掉了(我 -1 都没判啊)。
大概就是排序之后全部右移一位,然后把最大的数于最小的数配。
现在想想确实是这样啊。
这里给出证明:
假设排序后数组为
cpp
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 30;
int ans[maxn];
struct E
{
int id, x;
inline bool operator < (const E& other) const
{
return this->x < other.x;
}
} aa[maxn];
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
{
scanf("%d", &aa[i].x);
aa[i].id = i;
}
sort(aa + 1, aa + n + 1);
for(int i = 1; i < n; ++i)
ans[aa[i].id] = aa[i+1].x;
ans[aa[n].id] = aa[1].x;
for(int i = 1; i <= n; ++i)
printf("%d ", ans[i]);
return 0;
}
所以为什么