递归 int find_kth(vector<int>& nums1, int begin1, int size1, vector<int>& nums2, int begin2, int size2, int k) { size1 = min(k, size1);//第k大最多只要前k个 size2 = min(k, size2); if (k == 1) { return min(nums1[begin1], nums2[begin2]); } if (size…
(找第k大的数) 给定一个长度为1,000,000的无序正整数序列,以及另一个数n(1<=n<=1000000),接下来以类似快速排序的方法找到序列中第n大的数(关于第n大的数:例如序列{1,2,3,4,5,6}中第3大的数是4). #include <iostream> using namespace std; int a[1000001],n,ans = -1; void swap(int &a,int &b) { int c; c = a; a = b; b…
The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feel…
int get_kth(int l,int r) { if (l==r) return a[r]; ]; while (i<j) { while (a[i]<mid) i++; while (a[j]>mid) j--; if (i<j) { swap(a[i],a[j]); i++; j--; } } if (k<=j) return get_kth(l,j); if (k>=i) return get_kth(i,r); }…