Rose is a professor of music at the University of Melody. She has organized a group singing competition for the students of her class. Rose decides the initial size of the groups. The competition is organized in such a way that all the groups will be singing on stage together at the same time. The music department has some mics to distribute among the groups. Each group will be allotted exactly one mic. In case they end up with surplus mics, Rose will split the groups in such a way as to minimize the number of students sharing a single mic. Each initial group can only be split into two. However the new groups that are formed can be split further if necessary. Rose wishes to find the number of students in the largest group that is sharing a mic after the regrouping process.Write an algorithm to help Rose calculate the number of students in the largest group that is sharing a mic. code in java
Answers
Answered by
0
Answer:
nO BRO did not understand
Explanation:
Answered by
0
An algorithm to help Rose calculate the number of students in the largest group that is sharing a mic.
- Since the end case requires dividing the array at most (k-n) times, In order to resolve this, use a priority queue. Loop (k-n) times, inserting one element back into the queue after splitting it in half in each iteration.
- And following (k-n) iteration, you simply need to select an element from the queue.
JAVA CODE
import java.io.*;
public class GFG{
static int maxGroup(int n, int m)
{
if (n >= 2 * m)
return n;
if (m >= 2 * n)
return m;
if ((m + n) % 3 == 0)
return (m + n) / 3;
int ans = (m + n) / 3;
m %= 3;
n %= 3;
if (m > 0 && n > 0 && (m + n) >= 3)
ans++;
return ans;
}
static public void main (String[] args)
{
int n = 4, m = 5;
System.out.println(maxGroup(n, m));
}
}
#SPJ2
Similar questions