ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1423. Басня о строке

Показать все сообщения Спрятать все сообщения

Hint ASK 3 мар 2010 21:29
Similar to <http://en.wikipedia.org/wiki/Rabin-Karp_string_search_algorithm>

Think of a string as coefficients of a polynomial H (calculated modulo some, say, 31-bit prime P, e.g., 2000000011). Take a random X and calculate H(X). Take the second string and calculate its code. To calculate the value for a shifted string simply add to it A*(1-X^n), where A is the i-th character (this is a simplification of the needed steps: subtract A*X^{n-1}, multiply by X, and add A). If value for the shifted string is the same as for the first, output i (if P is large you don't even need to check).
Re: Hint svr 3 мар 2010 22:45
Kruto!
Re: Hint Anton 29 ноя 2011 07:05
Very nice idea. But I used some edition in my solution: I don't use any prime number, I just use unsigned long long type without any modulo operation. So the type overflow does its work well enough and It's no nessesary to check strings for eq.