Problem 3: In the country of WeirdLand, there is only one barber shop. In the shop there are 3 barbers, Alpha, Beta and Gamma, who are not always efficient as employees. All the customers are seated in a waiting area, each customer has a card which has a unique integral ID. For calling next person from the waiting area each barber has his own weird way: Alpha: He will call either the person with least ID from the waiting area of the one with max ID. Min or Max is decided randomly by him (assume 50% probability for each min or max). Beta: He will choose a ‘k’ and will call the kth smallest ID, (Kth ID when all IDs are arranged in ascending order). K is chosen randomly from the number of persons available in waiting area (1 <= K <= Total persons)
int n;
int customers_id[n];
int i1=0;
int a_call_id1=customers_id[0];
int a_call_id2=customers_id[0];
int b_call_id1=customers_id[0];
int g_call_id=0;
Alpha{
while(true):
if(customers_id[i]<a_call_id1):
a_call_id1=customers_id[i];
if(customers_id[i]>a_call_id2):
a_call_id2=customers_id[i];
}
Beta{
while(true):
if(customers_id[i]<b_call_id1):
b_call_id1=customers_id[i];
}
Gamma{
while(true):
g_call_id1=median.(customers_id);
}
Comments
Leave a comment