Beautiful programming book note_sorting of 1.3 pieces of pancakes (Supplement)

Source: Internet
Author: User

A few months ago I wrote a ranking of the beautiful Reading Notes of programming _ 1.3 pieces of pancakes, listing the examples in the book }, to reduce the number of searches from the original 172126 to 29, we thought that to further reduce the number of searches, we had to strengthen the pruning conditions and add a large amount of code. In fact, we only need to change one of them, the number of searches can be reduced to 11. Traverse all possible arrays and find 1st ...... The total time used for the number of 10th pancakes also dropped from 38 seconds to 21 seconds.

 

 

Changes:

1.3 _ pancake_final 148th rows

For(IntPos = 1, last_swap = cake_swap [step ++]; pos <size; ++ pos ){

Changed:

For(IntPos = size-1, last_swap = cake_swap [step ++]; pos> 0; ++ pos ){

The simple modification only changes the search order, but greatly improves the search efficiency.

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.