B. Bogosort
题意
给您一个数组a1,a2,…,an。如果对于每对索引i <j,条件j-aj≠i-ai成立,则数组是好的。您可以改组这个数组以使其变好吗?随机排列数组意味着可以对其元素进行任意重新排序(也可以不选择初始顺序)。
思路
从大到小倒序输出。
代码实现
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int main(void){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int a[n];
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a+1,a+1+n,cmp);
for(int i = 1; i <= n; i++) cout<<a[i]<<" ";
cout<<endl;
}
return 0;
}