#include <iostream> #include <cstring> #include <cmath> #include <ctime> #include <cstdio> #include "windows.h" #include <algorithm> using namespace std; const int sup = 1010; int aryA[sup], aryB[sup]; /** 二分法求数组aryA从s1到e1,aryB从s2到e2,第k大的数 思路如下: 1,首先取二者的中点位置idxA = k / 2, idxB = k / 2, 然后判断aryA[idxA]和aryB[idxB]的大小关系, 假如相等,那么表示已经找到,为aryA[idxA];否则,不失一般性: 假设aryA[idxA] < aryB[idxB],那么第k大的元素一定在aryB的 前k / 2个数中,取aryB的前k / 4的元素,idxB = k / 4, aryA后k / 4 的元素,idxA = idxA + k / 4;重复上述过程,不断二分。 程序中求的是第k小的数 */ bool myCMP(int a, int b) { return a < b; } int Bsearch(int s1, int e1, int s2, int e2, int kth) { int idxA = (s1 + e1) >> 1; int idxB = (s2 + e2) >> 1; int lenA = idxA - s1 + 1; int