UVa 188:perfect Hash

Source: Internet
Author: User
Tags floor function hash integer

Topic Link:

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=124

Type: Hash

Original title:

Perfect Software, INC has obtained a government contract to examine text flowing through a high-speed network for the OCC Urrence of certain words. Your boss, Wally Perfect, has designed a parallel processing system which checks each word against a group of small perfec T hash tables.

A perfect hash function maps its input directly to a fully occupied table. The Your job is to construct the perfect hash functions from the lists of words into each table. The hash function is the form

, where C is a positive integer for you are to discover, W was an integer representation of ' an ' input word, and n is the length of the table. C must be as small as possible. Note that

is the floor function and this is the largest integer.

Here are Wally ' s notes on the subject:

Let

consist of positive integers

. The problem is to find the smallest positive integer C such that

For all

.

C must be a multiple the at least one element of W.

If some

For all

,

Then the next largest C that could resolve the conflict are at least

Since all such conflicts must being resolved, it is advantageous to choose the largest candidate the among as The next C to test.

You are are to convert each of word to a and by processing the from left to right. Consider ' a ' to is 1, ' B ' to be 2,

, ' Z ' to be 26. Use 5 bits for each letter (shift left by 5 or multiply by 32). Thus ' A ' = 1, ' BZ ' =

.

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.