Algorithm review--hash table + binary search (poj2549)

Source: Internet
Author: User

Moving handouts ~ Moving handouts ~

Binary search feels like it's all about violence every time. 2333, mainly used for descending times · Binary can be used to reduce complexity when complexity is an exponential level • In fact, there are not many examples of special test binary ... is generally a small optimization in the middle ...

Then the binary search is often used with hash tables • Especially when it comes to the problem of equation class ...

The hash table will not say it ... After all, it's quite simple ... Do not know to read the following code on the line, a binary and hash table combined with the classic equation model problem ...

Descriptiongiven S, a set of integers, find the largest d such that A + B + c = d where a, B, C, and D is distinct elemen TS of S.inputseveral S, each consisting of a line containing an integer 1 <= n <= indicating the number of Elem Ents in S, followed by the elements of S, one per line. Each element of S is a distinct integer between-536870912 and +536870911 inclusive. The last line of input contains 0.OutputFor each S, a single line containing d, or a single line containing "no solution". Sample Input
52 3 5 7 1252 16 64 256 10240
Sample Output
12NO Solution

By A+b+c=d naturally to the a+b=d-c, and then all a+b stored in the hash table, then press D from the big to the small d-c find can be, the first to find is the largest answer •

Also note that storing a subscript is more important because ABCD cannot be the same element

Algorithm review--hash table + binary search (poj2549)

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.