用这个去写快排模板竟然能AC一个点!!! 上代码
#include <cstdio>
#include <algorithm>
#include <ctime>
//#define TIME_TEST
#define MAXN 100005
int arr[MAXN];
int main()
{
int n; scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", &arr[i]);
#ifdef TIME_TEST
clock_t tt = clock();
#endif // TIME_TEST
//猴子排序
bool ok = false;
while(!ok){
std::random_shuffle(arr, arr + n);
ok = true;
for(int i = 1; i < n; ++i)
if(arr[i] < arr[i - 1]){
ok = false;
break;
}
}
//猴子排序结束
#ifdef TIME_TEST
tt = clock() - tt;
//printf("Use Time:%d\n", (int)tt);
#endif // TIME_TEST
ok = false;
for(int i = 0; i < n; ++i){
if(ok) putchar(' ');
else ok = true;
printf("%d", arr[i]);
}
putchar('\n');
return 0;
}
挺好的去试试