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

Folding Game

Folding Game

Alice and Bob are playing a game. Alice places a rectangular piece of paper in front of Bob with width \textbf{W} and height \textbf{H}. Then she proceeds to fold the paper \textbf{N} times. Each fold is either horizontal or vertical. Folding the paper horizontally leaves another rectangle of the same width \textbf{W} and smaller height \textbf{h}. Similarly, a vertical fold leaves a rectangle with same height \textbf{H} and smaller width \textbf{w}. In the end, Alice puts her finger on some point on the resulting rectangle and asks '\textit{Bob, how many layers of paper are directly beneath my finger?}'. \InputFile There will be several test cases in the input. Each test case will begin with a line with three integers: \textbf{W H N} Where \textbf{W} and \textbf{H} (\textbf{0} < \textbf{W}, \textbf{H} ≤ \textbf{1,000,000}) are the width and height of the paper, and \textbf{N} (\textbf{0} ≤ \textbf{N} ≤ \textbf{20}) is the number of folds. \textbf{W} and \textbf{H} are guaranteed to be even. On each of the subsequent N lines there will be a letter and a number, separated by a single space: \textbf{D K} The letter \textbf{D} is one of \{'\textbf{T}', '\textbf{B}', '\textbf{L}', '\textbf{R}' \} indicating whether the fold is from the Top, Bottom, Left or Right. It will always be capital. The number K indicates where Alice makes the fold, measured from the given edge. For example, if \textbf{D} is '\textbf{T}', then Alice starts with the paper lying flat, lifts the TOP edge and folds it downward. K is guaranteed to be on the paper, and it is guaranteed to be even. On the final line of each case there will be two integers: \textbf{X Y} Which indicate the point where Alice puts her finger. This is measured from the bottom left corner, with \textbf{X} being the distance towards the right, and \textbf{Y} being the distance towards the top. The point (\textbf{X}, \textbf{Y}) is guaranteed to be on the fully folded paper. Both \textbf{X} and \textbf{Y} are also guaranteed to be odd. Since \textbf{W}, \textbf{H} and \textbf{K} are all even, this assures that the point (\textbf{X}, \textbf{Y}) will not be over any edge or fold. The input ends with a line with three \textbf{0}s. \OutputFile For each case output a single integer on its own line, indicating the number of layers of paper at the given point (\textbf{X}, \textbf{Y}). Output no extra spaces, and do not separate answers with blank lines.
Лимит времени 1 секунда
Лимит использования памяти 32 MiB
Входные данные #1
10 10 1
B 4
5 1
10 10 1
B 4
7 5
10 10 1
T 6
3 1
10 10 1
T 6
9 3
14 10 2
L 4
R 4
3 3
0 0 0
Выходные данные #1
2
1
1
2
3
Источник 2011 ACM ICPC Southeast USA Regional Programming Contest