Test instructions: an arrangement of input 1~n, which can be exchanged for 2 integers at a time, asking for a small number of interchanges required to make the arrangement into a circular arrangement of 1~N. (3≤n≤500)
solution:(again I did not hit the code, light Think and look at the time of the problem ~qwq) because N is very small, can be violent enumeration of the target ring arrangement, so greedy exchange-the element x directly with its target position on the elements of the interchange, so that at least 1 elements of the correct Position. If X is exchanged with other k-elements first, it is possible to get the correct arrangement of the k+1 elements, so that there is no prior strategic advantage.
In addition, on the Internet about this topic there is also a chain-like sequence to find the ring, I do not understand. If anyone can explain to me, I will be extremely grateful!? (^∀^)? (this is not a joke, even if it is my afo, I will come back from now and then to See.) '? (?)? ´) after all these are the records of their own hard work, haha ~) UVA 10570 meet with Aliens Alien party
Attention-the topic is first from the direct inefficient way of thinking, and then step by step optimization, so violence will! 's Finger licking (=^?ω? ^=) 丿
"uva 10570" Meeting with aliens (algorithmic Efficiency – brute Force + greed)