CF1312B.Bogosort
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an. Array is good if for each pair of indexes i<j the condition j−aj=i−ai holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a=[1,1,3,5], then shuffled arrays [1,3,5,1], [3,5,1,1] and [5,3,1,1] are good, but shuffled arrays [3,1,5,1], [1,1,3,5] and [1,1,5,3] aren't.
It's guaranteed that it's always possible to shuffle an array to meet this condition.
给你一个数组 a1,a2,…,an。若对任意下标对 i<j 均满足 j−aj=i−ai,则称该数组是“好的”。你能否重排(即任意打乱)这个数组,使其变为“好的”?所谓重排,是指任意重新排列其元素(保持原顺序也是一种合法的重排方式)。
例如,若 a=[1,1,3,5],则重排后的数组 [1,3,5,1]、[3,5,1,1] 和 [5,3,1,1] 是“好的”,但 [3,1,5,1]、[1,1,3,5] 和 [1,1,5,3] 不是。
题目保证:总存在一种重排方式,使得数组满足该条件。
输入格式
The first line contains one integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤100) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤100).
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100)。
输出格式
For each test case print the shuffled version of the array a which is good.
对于每个测试用例,输出数组 a 的一个满足条件的打乱版本。
输入输出样例
输入#1
3 1 7 4 1 1 3 5 6 3 2 1 5 6 4
输出#1
7 1 5 1 3 2 4 6 1 3 5
输入解题思路,AI测评打分。不知道怎么写?