Update exam/packet.tex

This commit is contained in:
2025-11-28 12:16:13 -06:00
parent 2f25f1bfe3
commit b2c580746b

View File

@@ -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}