编程介的小学生 2017-11-14 09:35 采纳率: 20.5%
浏览 365
已结题

Folding Game

Problem Description
Alice and Bob are playing a game. Alice places a rectangular piece of paper in front of Bob with width W and height H. Then she proceeds to fold the paper N times. Each fold is either horizontal or vertical. Folding the paper horizontally leaves another rectangle of the same width W and smaller height h. Similarly, a vertical fold leaves a rectangle with same height H and smaller width w.
In the end, Alice puts her finger on some point on the resulting rectangle and asks 'Bob, how many layers of paper are directly beneath my finger?'.

Input
There will be several test cases in the input. Each test case will begin with a line with three integers:
W H N
Where W and H (0 < W,H ≤ 1,000,000) are the width and height of the paper, and N (0 ≤ N ≤ 20) is the number of folds. W and 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:
D K
The letter D is one of { ‘T’, ‘B’, ‘L’, ‘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 D is ‘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:
X Y
Which indicate the point where Alice puts her finger. This is measured from the bottom left corner, with X being the distance towards the right, and Y being the distance towards the top. The point (X,Y) is guaranteed to be on the fully folded paper. Both X and Y are also guaranteed to be odd. Since W, H and K are all even, this assures that the point (X,Y) will not be over any edge or fold.
The input ends with a line with three 0s.

Output
For each case output a single integer on its own line, indicating the number of layers of paper at the given point (X,Y). Output no extra spaces, and do not separate answers with blank lines.

Sample Input
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

Sample Output
2
1
1
2
3

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?