Блог пользователя I_am_Drew

Автор I_am_Drew, история, 6 лет назад, По-английски

I have come up with (invent) a new list hashing algorithm that you can use to hash lists whenever you want. The secret is simple:

Suppose B is a dict (map) ar = list (vector)

Then for a list consisting of two elements, we need to match this number:

B[pow(ar[0], 37, 1000000007) + pow(ar[1], 43, 1000000007)] = [ar[0], ar[1]]

So we have mapped a list of 2 elements to a number!!!

The more items in the list, the further we can add pow(ar[i], P_i, 1000000007), where i is the trace. index in the list (vector), and P_i is the trace. Prime number.

With this hashing of lists (vectors), we can with a probability of 95-99% drive the problem to OK without much bother!!!

I hope the article was useful!

  • Проголосовать: нравится
  • -34
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Hm, I will try this on problem that I haven't solved a week ago!

Thanks!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

It is genius! But why you use 37 and 43? I will hack you in future codeforces rounds by this!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

What do you think about this algorithm? Is it quite good or not?)

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

what is the "pow"???

powAR or powER ????

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится -10 Проголосовать: не нравится

by the way, it is the best idea in whole competetive programming!!!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -7 Проголосовать: не нравится

This is very interesting !

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

"I hope the article was useful!"

do not hope. Be sure it was useful!!!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I don’t understand the idea... can anybody(Or I_am_Drew)explain it better please?

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

So how to compare subarrays when they start at different places?

F.e $$$arr[i..i+k-1], arr[j..j+k-1], i \lt \gt j$$$

In traditional hashing, you multiply hash by $$$p^{BIGNUMBA-i}$$$ or smth to compare.