stuck on this question

Правка en3, от osource, 2020-10-01 17:52:05

You have 2 arrays A and B each of size n, that contains integers from 1 to n inclusive. In one move, you can swap corresponding elements of two arrays. Determine if it is possible to have such series of operations (possibly zero) that both arrays contain integers from 1 to n exactly once, if possible print the series of operations (ie indices on which you apply the operations) and -1 if not possible.

eg

A = 3 1 2 1 2 B = 5 4 4 5 3

ans = 3 4

explanation : after operations

A = 3 1 4 5 2 B = 5 4 2 1 3

Can someone tell me the approach/pseudocode for this?

Теги #array

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский osource 2020-10-01 17:52:44 6
en3 Английский osource 2020-10-01 17:52:05 19
en2 Английский osource 2020-10-01 17:51:14 1
en1 Английский osource 2020-10-01 17:50:54 599 Initial revision (published)