In computer science,bogo sorting (bogo-sort) is an impractical and primitive sorting algorithm, which is equivalent to throwing a pile of cards on the table and checking to see if the cards are neatly arranged, if not thrown again. The name is derived from Quantum bogodynamics, also known as Bozo sort, blort sort or monkey (see Infinite monkey theorem).
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/*int buf[10];inline void write (int i) {int p = 0;if (i = = 0) p++; else while (i) {buf[p++] = i% 10;i/= 10;} for (int j = p-1; J >=0; j--) Putchar (' 0 ' + buf[j]); printf ("\ n");}*///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intA[MAXN];intB[MAXN];intVIS[MAXN];intN;intCnt=0;intMain () {n=read (); for(intI=0; i<n;i++) A[i]=read (); while(1) { for(intI=0; i<n;i++) B[i]=A[i]; intflag=0; for(intI=0; i<n-1; i++) if(b[i]>b[i+1]) {flag=1; Break; } if(!flag) Break; CNT++; memset (Vis,0,sizeof(VIS)); for(intI=0; i<n;i++) { while(1) { intK=rand ()%N; if(Vis[k])Continue; A[i]=B[k]; VIS[K]=1; Break; } }} cout<<cnt<<Endl; for(intI=0; i<n;i++) cout<<a[i]<<" "; cout<<Endl;}
Monkey sort but there's no use for 233