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)