From b2c580746b93d84670f25f28ca6b3908442fb8eb Mon Sep 17 00:00:00 2001 From: problsolv Date: Fri, 28 Nov 2025 12:16:13 -0600 Subject: [PATCH] Update exam/packet.tex --- exam/packet.tex | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/exam/packet.tex b/exam/packet.tex index ef77f62..0b10f7d 100644 --- a/exam/packet.tex +++ b/exam/packet.tex @@ -244,7 +244,7 @@ Your task is to determine if there exists any valid path from (1,1) to (N,M) obe \problem{Problem 8: Staircase} \textit{Difficulty: Medium} -There is a staircase with N steps. Each step is labelled with a 6 or a 7. Simon starts at step 1 and wishes to reach the top step (Step N). If a step is labelled with a 6, Simon may go up 1 or 2 steps. If a step is labelled with a 7, Simon can move up exactly 1 step. Your job is to find the total number of distinct ways Simon can reach the top step N, given these rules. +There is a staircase with N steps. Each step is labelled with a 6 or a 7. Simon starts at step 1 and wishes to reach the top step (Step N). If a step is labelled with a 6, Simon may go up 1 or 2 steps. If a step is labelled with a 7, Simon can move up exactly 1 step. Your job is to find the total number of distinct ways Simon can reach the top step N from , given these rules. \inputformat \begin{itemize} @@ -254,7 +254,7 @@ There is a staircase with N steps. Each step is labelled with a 6 or a 7. Simon \outputformat \begin{itemize} - \item Output the number of distinct ways Simon can reach the top step N. Note that Simon starts at step 1. + \item Output the number of distinct ways Simon can reach the top step N. \end{itemize} \examples @@ -292,5 +292,65 @@ There is a staircase with N steps. Each step is labelled with a 6 or a 7. Simon Explanation 3: There is only one way to get to the top (which Simon is already at). \end{verbatim} -\end{document} +% ========================= Problem 9 ========================= +\newpage +\problem{Problem 9: Showering} +\textit{Difficulty: Medium} + +We all know that CS students don't shower often. In fact, Simon showers about 6 to 7 times every year, a practice of discipline and optimization. To motivate himself to shower, Simon invented a mini-game involving a sequence made only of 6s and 7s. +Before every shower cycle, Simon stares at the sequence and simulates a “cleaning process.” He believes that every time he cleans up the sequence, he cleans up his soul enough to deserve a shower.\newline\newline +You are given a string S of length N consisting only of 6 and 7.\newline\newline +Simon scans the string left to right, performing what he calls a “pre-rinse sweep." Whenever Simon encounters the pattern “67”, he considers that a sign of impurity — +the 6 is “dirtier” than the 7, so they must be flipped to “76” on the spot. +This change happens immediately, because Simon believes cleanliness must spread instantly. After reaching the end, Simon restarts the sweep from the beginning, repeating passes until there are no more “67” pairs, meaning the sequence has reached maximum spiritual hygiene. Your task is to determine the number of flips Simon must do to achiece spiritual hygiene. + +\inputformat +\begin{itemize} + \item The first line consists an integer N($1 \leq N \leq 2 * 10^5$), the length of the sequence + \item The second line will consist of a string S, with length N +\end{itemize} + +\outputformat +\begin{itemize} + \item Output the number of steps required to achieve spiritual cleanliness +\end{itemize} + +\examples +\begin{verbatim} + Input 1: + 4 + 6677 + + Output 1: + 4 + + Explanation 1: + First Swap: 6677 -> 6767 + Second Swap: 6767 -> 6776 + Third Swap (returns to beginning): 6776 -> 7676 + Fourth Swap: 7676 -> 7766 + + Input 2: + 5 + 77766 + + Output 2: + 0 + + Explanation 2: + The sequence is already spiritually clean + + Input 3: + 5 + 67676 + + Output 3: + 3 + + Explanation 3: + First Swap: 67676 -> 76676 + Second Swap: 76676 -> 76766 + Third Swap (return to beginning): 76766 -> 77666 +\end{verbatim} +\end{document} \ No newline at end of file