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

Texas hold `em

Texas hold `em

Техасский Холдем - одна из стандартных покерных игр, которая появилась в Техасе, США. В нее играют стандартной колодой из \textbf{52 }карт с \textbf{4} мастями (пики, червы, бубны и кресты) по \textbf{13} карт в каждой (\textbf{A}, \textbf{K}, \textbf{Q}, \textbf{J} и \textbf{10}\{\textbf{2}), без джокеров. Игра проходит следующим образом. Сначала каждый игрок получает по две карты лицом вниз. Они называются закрытыми или карманными картами, их нельзя открывать до полного вскрытия карт. Затем дилер кладет три карты лицом вверх - общие карты, то есть карты, которые являются общими для всех игроков. Эти три карты называются флопом. Следующая за флопом общая карта называется турном, а пятая - ривером. После ривера игра переходит ко вскрытию карт. Все игроки открывают все свои карты. Каждый игрок выбирает пять из семи карт, то есть их две закрытые карты и пять общих формируют руку. Игрок с сильнейшей рукой выигрывает игру. Существует десять возможных рук, перечисленных ниже от сильнейшей до самой слабой: \begin{itemize} \item \textit{Роял Стрит Флеш}: \textbf{A}, \textbf{K}, \textbf{Q}, \textbf{J} и \textbf{10} одной масти. Это особый случай стрит флеша. \item \textit{Стрит Флеш}: Пять последовательных карт (например \textbf{7}, \textbf{6}, \textbf{5}, \textbf{4} и \textbf{3}) одной масти. \item \textit{Четверка}: Четыре карты одного ранга. \item \textit{Фулл Хауз}: Три карты одного ранга плюс пара другого ранга. \item \textit{Флеш}: Пять карт одной масти, но не последовательных. \item \textit{Стрит}: Пять последовательных карт, но не одной масти. \item \textit{Тройка}: Три карты одного ранга. \item \textit{Две пары}: Две карты одного ранга и две другие карты другого ранга. \item \textit{Одна пара}: Только пара карт (две карты) одного ранга. \item \textit{Высшая карта}: Любая другая рука. \end{itemize} Карты \textbf{J}, \textbf{Q} и \textbf{K} в последовательности будем трактовать как \textbf{11}, \textbf{12} и \textbf{13} соответственно. \textbf{A} считается по рангу следующим после \textbf{K} и предшествующим \textbf{2}, так что обе последовательности \textbf{A}-\textbf{K}-\textbf{Q}-\textbf{J}-\textbf{10} и \textbf{5}-\textbf{4}-\textbf{3}-\textbf{2}-\textbf{A} возможны (но не \textbf{3}-\textbf{2}-\textbf{A}-\textbf{K}-\textbf{Q} или подобные). Если более одного игрока имеют одинаковые руки, то сравниваются ранги карт. Основная идея - сравнить сначала образовавшиеся множества (пары, тройки или четверки), а затем остальные карты одна за другой от наибольшей до наименьшей по рангу пока не нарушится равенство рук. Более точно: \begin{itemize} \item \textit{Royal straight flush}: (ties are not broken) \item \textit{Straight flush}: Compare the highest-ranked card. \item \textit{Four of a kind}: Compare the four cards, then the remaining one. \item \textit{Full house}: Compare the three cards, then the pair. \item \textit{Flush}: Compare all cards one by one. \item \textit{Straight}: Compare the highest-ranked card. \item \textit{Three of a kind}: Compare the three cards, then the remaining two. \item \textit{Two pairs}: Compare the higher-ranked pair, then the lower-ranked, then the last one. \item \textit{One pair} : Compare the pair, then the remaining three. \item \textit{High card}: Compare all cards one by one. \end{itemize} Порядок рангов \textbf{A}, \textbf{K}, \textbf{Q}, \textbf{J}, \textbf{10}, \textbf{9}, ... , \textbf{2} от наибольшего до наименьшего, except for \textbf{A} next to \textbf{2} in a straight regarded as lower than \textbf{2}. Note that there are exceptional cases where ties remain. Also note that the suits are not considered at all in tie-breaking. Here are a few examples of comparison (note these are only intended for explanatory purpose; some combinations cannot happen in Texas Hold 'em): \begin{itemize} \item \textbf{J}-\textbf{J}-\textbf{J}-\textbf{6}-\textbf{3} and \textbf{K}-\textbf{K}-\textbf{Q}-\textbf{Q}-\textbf{8}. \end{itemize} The former beats the latter since three of a kind is stronger than two pairs. \begin{itemize} \item \textbf{J}-\textbf{J}-\textbf{J}-\textbf{6}-\textbf{3} and \textbf{K}-\textbf{Q}-\textbf{8}-\textbf{8}-\textbf{8}. \end{itemize} Since both are three of a kind, the triples are considered first, \textbf{J} and \textbf{8} in this case. \textbf{J} is higher, hence the former is a stronger hand. The remaining cards, \textbf{6}-\textbf{3} and \textbf{K}-\textbf{Q}, are not considered as the tie is already broken. \begin{itemize} \item \textbf{Q}-\textbf{J}-\textbf{8}-\textbf{6}-\textbf{3} and \textbf{Q}-\textbf{J}-\textbf{8}-\textbf{5}-\textbf{3}. \end{itemize} Both are high cards, assuming hands not of a single suit (i.e. flush). The three highest-ranked cards \textbf{Q}-\textbf{J}-\textbf{8} are the same, so the fourth highest are compared. The former is stronger since \textbf{6} is higher than \textbf{5}. \begin{itemize} \item \textbf{9}-\textbf{9}-\textbf{Q}-\textbf{7}-\textbf{2} and \textbf{9}-\textbf{9}-\textbf{J}-\textbf{8}-\textbf{5}. \end{itemize} Both are one pair, with the pair of the same rank (\textbf{9}). So the remaining cards, \textbf{Q}-\textbf{7}-\textbf{2} and \textbf{J}-\textbf{8}-\textbf{5}, are compared from the highest to the lowest, and the former wins as \textbf{Q} is higher than \textbf{J}. Now suppose you are playing a game of Texas Hold 'em with one opponent, and the hole cards and the op have already been dealt. You are surprisingly telepathic and able to know the cards the opponent has. Your ability is not, however, as strong as you can predict which the turn and the river will be. Your task is to write a program that calculates the probability of your winning the game, assuming the turn and the river are chosen uniformly randomly from the remaining cards. You and the opponent always have to choose the hand strongest possible. Ties should be included in the calculation, i.e. should be counted as losses. \InputFile Consists of multiple datasets, each of which has the following format: \textbf{YourCard_1 YourCard_2} \textbf{OpponentCard_1 OpponentCard_2} \textbf{CommunityCard_1 CommunityCard_2 CommunityCard_3} Each dataset consists of three lines. The first and second lines contain the hole cards of yours and the opponent's respectively. The third line contains the flop, i.e. the first three community cards. These cards are separated by spaces. Each card is represented by two characters. The fi rst one indicates the suit: \textbf{S} (spades), \textbf{H} (hearts), \textbf{D} (diamonds) or \textbf{C} (clubs). The second one indicates the rank: \textbf{A}, \textbf{K}, \textbf{Q}, \textbf{J}, \textbf{T} (\textbf{10}) or \textbf{9 }- \textbf{2}. The end of the input is indicated by a line with "\textbf{#}". This should not be processed. \OutputFile Print the probability in a line. The number may contain an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than \textbf{10^\{-6\}}.
Лимит времени 5 секунд
Лимит использования памяти 256 MiB
Входные данные #1
SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5
#
Выходные данные #1
1.00000000000000000000
0.34444444444444444198
0.63030303030303025391
Источник 2012 JAG Practice Contest for ACM-ICPC Asia Regional, AtCoder, November 4; 2013 Petrozavodsk Winter Training Camp, January 26, Problem E