You have 20 white and 13 black balls in a bag. You pull out 2 balls one after another. If you are a ball of light, then you can replace it with a black ball. Once you take out the balls, keep reducing. What would be the ball in the bag?
I wouldn’t turn up one day. So when he came next I demanded explanation from him. He told me the following story:
It is a carrot that has been banged up. However, a careful gentleman has been given to him for damages. The number of eggs was not reduced between 50 and 100. It was also a rule. , but if it counted by 5's at a time, it remained 3 eggs at 10 cent a piece. The gentleman made some quick calculations and paid peddler adequately.
How much did the gentleman pay for eggs?
The pattern is given. It is assumed that r * c is always odd.
')
Examples:
Input:
1 3 5
2 6 9
3 6 9
Output: Median is 5
If we put the array A [] = 1 2 3 3 5 6 6 9 9
Input:
1 3 4
2 5 6
7 8 9
Output: Median is 5
We give you your opinion. It can be seen that it has reached the maximum 10 (limit) times.
Examples:
Input: N = 7, D = 3
Output: 3/3 + 3 + 3
Explanation: 3/3 = 1, and 1 + 3 + 3 = 7
This is the minimum expression.
Input: N = 7, D = 4
Output: (4 + 4 + 4) / 4 + 4
Explanation: (4 + 4 + 4) = 12, and 12/4 = 3 and 3 + 4 = 7
Also this is the minimum expression. Although
you may find another expression but that
expression can have only five 4's
Input: N = 200, D = 9
Output: Expression not found!
Explanation: Not possible within 10 digits.
Given an array of n positive integers and a number k. It is required to bring together the minimum number of swaps.
Input: arr [] = {2, 1, 5, 6, 3}, k = 3
Output: 1
Explanation:
To bring elements 2, 1, 3 together, swap element '5' with '3' such that final array will be:
arr [] = {2, 1, 3, 6, 5}
Input: arr [] = {2, 7, 9, 5, 8, 7, 4}, k = 5
Output: 2
// C++ program to find median of a matrix // sorted row wise #include<bits/stdc++.h> using namespace std; const int MAX = 100; // function to find median in the matrix int binaryMedian(int m[][MAX], int r ,int c) { int min = INT_MAX, max = INT_MIN; for (int i=0; i<r; i++) { // Finding the minimum element if (m[i][0] < min) min = m[i][0]; // Finding the maximum element if (m[i][c-1] > max) max = m[i][c-1]; } int desired = (r * c + 1) / 2; while (min < max) { int mid = min + (max - min) / 2; int place = 0; // Find count of elements smaller than mid for (int i = 0; i < r; ++i) place += upper_bound(m[i], m[i]+c, mid) - m[i]; if (place < desired) min = mid + 1; else max = mid; } return min; } // driver program to check above functions int main() { int r = 3, c = 3; int m[][MAX]= { {1,3,5}, {2,6,9}, {3,6,9} }; cout << "Median is " << binaryMedian(m, r, c) << endl; return 0; }
Source: https://habr.com/ru/post/350004/
All Articles