Monkey sort but there's no use for 233

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.