Guruh talabasi G’iyosxonov Mahmudxon
Download 18.82 Kb.
|
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 priority_queue int count = 0, median = -1; int medianindex = (R*C)/2; for(int i = 0; i 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 r=3; int c=3; vector {2, 6, 9}, {3, 6, 9}}; Solution obj; cout< } Download 18.82 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling