A convention center is hosting a meeting of large firms, which N number of CEOs will be attending, Each CEO is assigned an invitation ID from 0 to N-1. Each CEO has some favorite CEO whom they like. They will attend the meeting only if they can be seated next to the person they like. Plan this seating arrangement.
Write an algorithm to find the maximum number of CEOs who will attend the meeting
Answers
Answer:
Input: s[] = {1, 3, 0, 5, 8, 5}, f[] = {2, 4, 6, 7, 9, 9}
Output: 1 2 4 5
First meeting [1, 2]
Second meeting [3, 4]
Fourth meeting [5, 7]
Fifth meeting [8, 9]
Input : s[] = {75250, 50074, 43659, 8931, 11273, 27545, 50879, 77924},
f[] = {112960, 114515, 81825, 93424, 54316, 35533, 73383, 160252 }
Output : 6 7 1
The goal is to solve the issue using a greedy strategy, which is the same as the approach used to solve the Activity Selection Problem. To do this, first arrange the meetings according to their end times. Then, choose the one with the shortest end time as the starting point for your selections.
Use the steps provided to solve the issue using the strategy described above:
Sort all pairings (Meetings) by the second number in each pair, increasing (Finish time).
Choose the first meeting of the sorted pair to be the first Meeting in the space, push it into the result vector, and set a variable called time limit with, let's say, the second value (the finishing time) of the first selected meeting.
# Python 3 program to rearrange array such
# that odd indexed elements are greater.
def rearrange(arr, n):
# Common code for odd and even lengths
for i in range(0, n - 1, 2):
if (arr[i] > arr[i + 1]):
temp = arr[i]
arr[i] = arr[i + 1]
arr[i + 1] = temp
# If length is odd
if (n & 1):
i = n - 1
while(i > 0):
if (arr[i] > arr[i - 1]):
temp = arr[i]
arr[i] = arr[i - 1]
arr[i - 1] = temp
i -= 2
# Utility that prints out an
# array on a line
def printArray(arr, size):
for i in range(0, size, 1):
print(arr[i], end = " ")
print("\n")
# Driver Code
if __name__ == '__main__':
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = len(arr)
print("Before rearranging")
printArray(arr, n)
rearrange(arr, n)
print("After rearranging")
printArray(arr, n)
See more:
https://brainly.in/question/53945221
#SPJ1