eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Key to Magica`s diary

Key to Magica`s diary

He’s smart, he’s rich --- and he needs your help. Scrooge McDuck’s Number One Dime is stolen by Magica De Spell. Best Scotland Yard inspectors are working on this case but the only evidence they found is Magica’s accidentally dropped secret diary. Unfortunately, it is protected by some spell that prevents everybody from understanding its contents. That’s why they need you - the best mathematician of Duckburg. The first thing you noticed is that some words are occurring much more often than others and form some weird pattern. You’ve made a hypothesis that these words are part of Magica’s spell and decided to ignore them for future analysis. After that it became pretty obvious that some words in the diary are found next to each other quite often (such as ’Scrooge’ and ’McDuck’) while others will be located pretty much independent from each other. You believe that this is the key to Magica’s diary and want to check your idea. More precisely, word is a non-empty continuous sequence of English letters. Text may contain other symbols, you should consider them as spaces. Words are considered to be case-insensitive. Define \textbf{P(a)} as percentage of word \textbf{a} in the text (i.e. the number of \textbf{a} occurrences divided by the total number of words in the text). Similarly, you define \textbf{P(a,b)}as the rate of words \textbf{a} and \textbf{b} occurrences adjacent to each other (i.e. number of such occurrences divided by total number of adjacent word pairs in the text). Then \includegraphics{https://static.e-olymp.com/content/26/264118870c5ac0496db3baa0b92e7172b230f05b.jpg} will show you how dependent words \textbf{a} and \textbf{b} are. You are particularly interested in some pairs of words and want to check how dependent they are. Unfortunately, the diary is too large to do this analysis manually, so you decided to write a program to do that for you. \InputFile First line of input contains one integer number \textbf{N} --- the total number of lines in Magica’s diary (\textbf{1} ≤ \textbf{N} ≤ \textbf{4000}). Then \textbf{N}lines of text follow. Diary contains only English letters, brackets, punctuation marks (\textbf{0123456789.,:;-!?’()"}), ampersands and spaces. The total length of the text is less or equal than \textbf{500} KiB, and the length of each word is not more than \textbf{20}. The text also contains more than one non-magic word. \textbf{N+2}^nd line contains \textbf{K} --- the total number of 'magic' words that should be ignored (\textbf{0} ≤ \textbf{K} ≤ \textbf{100}). Next \textbf{K} lines contain these words, one per line, lowercase. \textbf{N+K+3}^rdline contains \textbf{Q} --- the total number of word pairs you're interested in (\textbf{0} ≤ \textbf{Q} ≤ \textbf{50000}). Then \textbf{Q} lines follow, each containing two lowercase words. \OutputFile For each query (\textbf{a}, \textbf{b}) you should output the value of \textbf{C(a, b)} as a floating point number on the separate line with absolute or relative precision of \textbf{10^\{-6\}}.
Лимит времени 1 секунда
Лимит использования памяти 256 MiB
Входные данные #1
3
I have lived through
some terrible things in my life,
some of which actually happened.
3
of
in
which
3
some actually
things life
lived through
Выходные данные #1
6.545454545454546
0.0
13.090909090909092
Источник ACM ICPC 2012-2013, NEERC, Moscow Subregion, Moscow, Sunday, October 21, 2012