Computer Science, asked by poojacute10, 7 months ago

Grooving Monkeys Problem Description N monkeys are invited to a party where they start dancing. They dance in a circular formation, very similar to a Gujarati Garba or a Drum Circle. The dance requires the monkeys to constantly change positions after every 1 second. The change of position is not random & you, in the audience, observe a pattern. Monkeys are very disciplined & follow a specific pattern while dancing. Consider N = 6, and an array monkeys = {3,6,5,4,1,2}. This array (1-indexed) is the dancing pattern. The value at monkeys[i], indicates the new of position of the monkey who is standing at the ith position. Given N & the array monkeys[ ], find the time after which all monkeys are in the initial positions for the 1st time. Constraints 1 a,b,c,d,e,f At t = 1 -> e,f,a,d,c,b a will move to 3rd position, b will move to 6th position, c will move to 5th position, d will move to 4th position, e will move to 1st position and f will move to 2nd position. Thus from a,b,c,d,e,f at t =0, we get e,f,a,d,c,b at t =1. Recursively applying same transpositions, we get following positions for different values of t. At t = 2 -> c,b,e,d,a,f At t = 3 -> a,f,c,d,e,b At t = 4 -> e,b,a,d,c,f At t = 5 -> c,f,e,d,a,b At t = 6 -> a,b,c,d,e,f Since at t = 6, we got the original position, therefore the answer is 6.

Answers

Answered by AnJanabhoiranjana808
0

Answer:

Kaisa Kaisa hai tu hi tu hi tu hi tu hi tu hi tu hi hai I am sorry I didn't get back to you earlier I am going to

Explanation:

Please Mark as brainlist

Answered by srija99kakollu
2

Answer:

def monkeys(a):

   y = a  

   x=[0]*len(a)  

   count=0

   while(x!=a):

       count+=1

       x=[0]*len(a)  

       for i in range(len(a)):

           x[a[i]-1] = y[i]

       y=x

   return(count)

T = int(input())    

for i in range(T):

   n = int(input())

   monk = list(map(int,input().split()))

   answer = monkeys(monk)

   print(answer)

Explanation:

python implementation

Similar questions