Guruh talabasi G’iyosxonov Mahmudxon


Download 18.82 Kb.
Sana01.04.2023
Hajmi18.82 Kb.
#1317423
Bog'liq
dasturlash


713-21-guruh talabasi G’iyosxonov Mahmudxon
Birinchi usutun elementlarini kamayishi bo`yicha tartiblangan n x m o`lchamlik matritsa va m elementli vektor berilgan.Matritsaning tartiblanganligini buzmagan holda matritsaga vektor yangi qator ko`rinishida joylashtirilsin
Dastur kodi:
#include
using namespace std;

class node{


public:
int data;
int row;
int col;
node(int d, int r, int c){
row = r;
col = c;
data = d;
}
};

class compare{


public:
bool operator()(node* a, node* b){
return a->data > b->data;
}
};

class Solution{


public:
int median(vector> &matrix, int R, int C){
priority_queue, compare>minheap;
int count = 0, median = -1;
int medianindex = (R*C)/2;
for(int i = 0; inode* temp = new node(matrix[i][0], i, 0);
minheap.push(temp);
}
while(count <= medianindex){
node* top = minheap.top();
minheap.pop();
int row = top->row;
int col = top->col;
median = top->data;
count++;
if(col+1 < C){
col++;
node* temp = new node(matrix[row][col], row, col);
minheap.push(temp);
}
}
return median;
}

};

int main()


{
int r=3;
int c=3;
vector> matrix={{1, 3, 5},
{2, 6, 9},
{3, 6, 9}};
Solution obj;
cout<return 0;
}
Download 18.82 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling