P2348 Sanguosha I (Shuffling & Dealing)
Description
A game of Sanguosha has $n$ players, and each player needs $4$ cards. The deck has $k$ cards, which must be shuffled before dealing. Each card has the following $3$ attributes:
1. Card type:
1) Basic: Sha ($\texttt{K}$), Shan ($\texttt{M}$), Tao ($\texttt{P}$), Jiu ($\texttt{W}$).
2) Non-delayed tactic: Juedou ($\texttt{B}$), Wanjian ($\texttt{A}$), Nanman ($\texttt{S}$), Wugu ($\texttt{C}$), Taoyuan ($\texttt{G}$), Chai ($\texttt{D}$), Shun ($\texttt{U}$), Tiesuo ($\texttt{T}$), Wuxie ($\texttt{N}$), Huogong ($\texttt{F}$), Wuzhong ($\texttt{E}$).
3) Delayed tactic: Bing ($\texttt{I}$), Le ($\texttt{K}$), Shandian ($\texttt{L}$).
4) Mounts ($\texttt{+,-}$).
5) Weapon: Liannu ($\texttt{LN}$), Qinggang ($\texttt{QG}$), Guding ($\texttt{GD}$), Hanbing ($\texttt{HB}$), Cixiong ($\texttt{CX}$), Wuliu ($\texttt{WL}$), Qinglong ($\texttt{QL}$), Zhangba ($\texttt{ZB}$), Guanshi ($\texttt{GS}$), Fangtian ($\texttt{FT}$), Yushan ($\texttt{YS}$), Qilin ($\texttt{LG}$).
6) Armor: Renwang ($\texttt{RW}$), Bazhen ($\texttt{BZ}$), Tengjia ($\texttt{TJ}$), Shizi ($\texttt{SZ}$).
2. Suit: one of $\texttt{C,H,S,D}$.
3. Rank: one of $\texttt{A,2,3,4,5,6,7,8,9,T,J,Q,K}$ (T stands for 10, in ascending order).
Shuffling method: After one shuffle, from top to bottom the order becomes
$\left\lfloor\dfrac{k}{2}\right\rfloor+1, 1, \left\lfloor\dfrac{k}{2}\right\rfloor+2, 2, \left\lfloor\dfrac{k}{2}\right\rfloor+3, 3, \ldots, k, \left\lfloor\dfrac{k}{2}\right\rfloor$
(if there is an odd number of cards, the last extra card is simply ignored).
Dealing method: Starting from the $1$-st card, from top to bottom give the $i$-th card to player $[(i-1)\mod n+1]$.
Given that the deck is shuffled $m$ times in total, determine which $4$ cards are dealt to player $p$.
Input Format
The input has $k+1$ lines.
The first line contains $4$ positive integers $n, k, m, p$.
Then follow $k$ lines, each with two strings. In the first string, the first character is the suit and the second character is the rank; the second string is the card type. When outputting the player’s cards, use the same format.
The meanings of $n, k, m, p$ are as described above.
Output Format
Output $4$ lines, each with one string, representing the $4$ cards owned by player $p$ (each line must include the card’s suit, rank, and type, in the same format as the input).
If there are not enough cards, output `Error:cards not enough`.
Explanation/Hint
Constraints: For $100\%$ of the testdata, $1\leqslant p\leqslant n\leqslant 1000, 1\leqslant k\leqslant 100000, 1\leqslant m\leqslant 80$.
Translated by ChatGPT 5