UVa 188:Perfect Hash

题目链接:

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

类型: 哈希

原题:

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

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

, where C is a positive integer you are to discover, w is 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 that for some real number R is the largest integer that is .

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 of at least one element of W.

If some

for all

,

then the next largest C that could resolve the conflict is at least

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

You are to convert each word to a number by processing each letter from left to right. Consider `a' to be 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' =

.

时间: 2024-04-15 17:38:16

UVa 188:Perfect Hash的相关文章

UVa 704:Colour Hash, 双向bfs

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=110&page=show_problem&problem=645 类型:隐式图搜索,双向bfs 原题: This puzzle consists of two wheels. Both wheels can rotate both clock and counter-clockwise. They contai

uva 188 - Perfect Hash

点击打开链接 题目意思: 说这个题目之前先让我喷喷,太尼玛恶心了一道水题装B 的好像很有技术含量,真的是恶心.                    题目给定一个字符串.每一个字符串由多个单词组成,现在有一个计算法则" a = 1 , b = 2 ...... z = 26   ,'a' = 1 , "bz" = 26*32^0 + 2*32^1 = 90 类似32进制的转换" 然后要求我们去求出每一单词的值w ,排序满足 W1<W2<.......&l

uva 188 - Perfect Hash 模拟

       这题只要读懂题就等于没难度了,完全照着题目给的公式模拟即可      要注意的就是末尾的多余空格.   /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #inc

UVa 10397:Connect the Campus (最小生成树)

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1338 题目: Problem E Connect the Campus Input: standard input Output: standard output Time Limit: 2 seconds Many new buildings are

UVa 10125:Sumsets

题目链接: UVa : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1066 poj :   http://poj.org/problem?id=2549 类型: 哈希, 二分查找 原题: Given S, a set of integers, find the largest d such that a

UVa 10282:Babelfish

题目链接: UVA: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1223 poj:      http://poj.org/problem?id=2503 类型: 哈希表 原题: You have just moved from Waterloo to a big city. The people her

UVa 10391:Compound Words

题目链接: UVa: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1332 zoj :  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=825 类型: Hash 原题: You are to find all the two-word

UVa 10887:Concatenation of Languages

链接: UVa :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1828 类型:  哈希表 原题: A language is a set of strings. And the concatenation of two languages is the set of all strings that a

UVa 10591:Happy Number

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1532 类型: 哈希表 原题: Let the sum of the square of the digits of a positive integer S0 be represented by S1. In a similar way, let