UVA 1608 not boring sequences (with summary of common algorithm design and optimization strategies)

Source: Internet
Author: User
UVA 1608 not boring sequences (with summary of common algorithm design and optimization strategies)

The purple book has such a problem:

It is not boring to call this sequence if there is at least one element in any successive subsequence of a sequence that appears only once. Enter a sequence of n elements to determine whether it is a boring sequence. n<=200000.

First, find the element AI that appears only once in the entire sequence. If you can't find it, it's boring. Otherwise, you can exit the current loop, recursively judging [1, i-1] and [I+1, N] is not a boring sequence. However, how to find AI is very important. If you start looking from one end, then the worst-case time complexity is O (n^2). And if you start looking at both ends, then the worst case becomes AI in the middle, the time complexity is O (NLOGN)! This is because in the middle of the search is slow, split up fast, and at both ends of the find up fast, divided up slowly. Sometimes it's important to use a good halfway meeting!

Here are the common algorithm design strategies and optimization strategies that are used in purple books (note that this is a design strategy, not an algorithm):

Construction method (tectonic solution),

Halfway through the method (usually better than many encounters),

Problem decomposition (two unrelated issues are split up and solved separately),

Equivalent conversion (simplification),

Assumptions (using symmetry to avoid discussion),

Using the data structure (accelerating the algorithm without changing the main algorithm),

A combination of several shapes (usually associated with a sliding window),

Two-point answer (the optimal value will be determined to determine the optimal value, also in the strategy),

Scanning method (with sequential enumeration method, which usually maintains some important quantities),

Enumeration Datum (looking for the optimal value based on the current datum, then the maximum value of all the benchmarks),

Sliding windows (Maintenance monotonicity, efficient removal of redundant state) and so on.

UVA 1608 not boring sequences (with summary of common algorithm design and optimization strategies)

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.