/**
  * @param matrix: a matrix of integers
  * @param k: an integer
  * @return: the kth smallest number in the matrix
  */
 int kthSmallest(vector<vector<int>> &matrix, int k) {
     if (matrix.size() < matrix[0].size()) {  // Height is smaller.
         return horizontal_search(matrix, k);
     } else {  // Width is smaller.
         return vertical_search(matrix, k);
     }
 }
Пример #2
0
struct vector *horizontal_rec(struct matrix *img, struct coords block, int win)
{
    int i = horizontal_search(img, block);
    if(i)
    {
        struct coords b1, b2;
        b1 = block, b2 = block;
        b1.h2 = i;
        b2.h1 = i;
        return vector_merge(vertical_rec(img, b1, 1), vertical_rec(img, b2, 1));
    }
    else
    {
        if(win)
            return vertical_rec(img, block, 0);
        else
        {
            struct vector *indivisible_block = vector_make(1);
            indivisible_block->data[0] = block;
            return indivisible_block;
        }
    }
}