![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
雨人---1001
我撸代码我快乐
展开
-
输出前m大个数,时间复杂度O(n+mlog(m))
#include<iostream> using namespace std;void swapM(int &a, int &b) { int tmp = a; a = b; b = tmp; }//用治处理 O(n+mlog(m)) //用O(n)把m大个数挪到右边,然后对这m个数排序再输出 void QuickSort(int a[], int s, int e) {原创 2017-08-13 15:36:31 · 2115 阅读 · 2 评论 -
寻找多元素
多元素定义:多元素即在数列中出现次数多于n/2的元素,即超过50% 性质:在一个序列中如果去掉2个不同的元素,那么原序列中的多元素,在新的序列中还是多元素,#include<stdio.h> #include<stdlib.h>int main() { int a[] = {3,1,1,2,3,1,3,3,3}; int i; //初始化 int count = 1原创 2017-07-30 10:50:49 · 282 阅读 · 0 评论