"uva 10570" Meeting with aliens (algorithmic Efficiency – brute Force + greed)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.