一些奇怪的板子

1、猴子排序(Monkey_Sort)

号称最优复杂度最低的排序算法

最快复杂度:(O(n))
最慢复杂度:(O(+infty))
平均复杂度:(O(n imes n!))

算法思路:
1、检查数据是否有序,若有序,goto 3;若无序,goto 2
2、随机打乱数据,goto 1
3、输出数据

代码:

struct Monkey_Sort{
	inline bool check(int *st,int *ed){
		int *now=st;
		while(now+1!=ed){
			if(*(now+1)<*now)
				return 0;
			now++;
		}
		return 1;
	}
	inline void sort(int *st,int *ed){
		while(!check(st,ed))
			random_shuffle(st,ed);
	}
}M;
原文地址:https://www.cnblogs.com/hzf29721/p/10016716.html