Hash function: mapping and algorithm, using random access of array

  • Mode problem
题目一:统计相同成绩(0~100的整数)的学生集中出现的分数
题目二:统计字符串中出现频率,找到最高频的字符
题目三:给出一段仅有大小写字母构成的字符串,找出使用频率最高的按键(输出大写)

f(x), x is a reference, name, f(x) records an attribute of this name, here is specific: the
first question, scoreTimes[score], initialized to 0, encounter score1, that is, scoreTimes[ score1]++.
The second question, charTimes[char] The
third question, charTimes[uppercase-'A'] is equivalent to charTimes[lowercase-'a'], where uppercase -'A' and lowercase -'a' are also a kind of mapping.
Simple like: x—>g(x)------>f(g(x))

  • Used, valid and invalid
问题一:给出一些足球队和其球员的收入,输出年薪超过m千万的球队
问题二:开门问题,第一次把一的倍数的门打开,第二次关上二的倍数,在之后打开三的倍数……多次之后问那些门关上了?
问题三:给出一些字符串,问当部分字符无效后,应输出什么结果?

The first one, used【team】=false, the
second one, open【the number of the door】=false, adjust once, reverse once and the
third one, delete (invalid) is equivalent to, first is invalid , And then give the used part is valid, and finally check the current invalid

  • Containment, combination problem
问题一:小李有一栋房子,三辆车,小王有三栋房子,四辆车,(假定车之间,房之间并无差别),试着验证小王的资产可以包含几个小李?
问题二:现又一些正整数,给出一个数M,问是否存在这样两个数之和等于M,且这两个数最接近。(15=7+8

The first one is to count Xiao Li's (car) and Xiao Wang's (car), ensuring that the latter is not less than the former.
Car — 0
room — 1
Xiao Li li[2]
Xiao Wang — wang[2] The
second one, the frequency (number 1), and the frequency (M-number 1) are not zero. Especially when these two numbers are the same, the frequency should not be too small.

  • Nested problem x—>g(x)------>f(g(x))
问题一:给出队伍的名称,字符串,以及多场得分,统计得分最高的队伍并输出
问题二:给出学生的编号,和一些成绩,计算并输出各科第一的学生

The first one, first, the name is mapped to a uniquely distinguishable number; the
first method knows all team names, records them in the name table, and uses subscript access (refers to) the
second method to set a hash function for the name, Hash [name] is the index subscript.
Finally, score [team] can be realized, score [hash [team]]

For the second question, if the number is like 201401, you can directly use it as a number subscript to map students.

Ranking Language mathematics English language
2001 2 3 1
2002 3 1 2
2005 2 3 2
2003 1 2 3

Get it—>rank [student] [subject]

Guess you like

Origin blog.csdn.net/qq_34890856/article/details/105676332