编程介的小学生 2017-04-05 04:19 采纳率: 20.5%
浏览 663
已采纳

DomiNo Grid

Dominoes are small, flat, rectangular-shaped game pieces. Domino pieces are usually twice as long as they are wide and are usually made to be exactly half as thick as they are wide so that they can stand on edge without falling over. If we push one end of a queue of dominoes, the whole queue will fall over.

Now, you will be given some descriptions of domino grid with a '.' indicating an open space and an uppercase 'X' indicating a domino and the force used on one domino. You are to compute the ending descriptions. The force consists of two parts : location and direction. There are 8 directions shown below.

direction abbreviation
West : W
NorthWest : V
North : N
NorthEast : Y
East : E
SouthEast : Q
South : S
SouthWest : J
The falling direction of the pushed domino is always the same as the force. Other dominoes will fall over if: 1) it's adjacent with a previous fallen domino. 2) it's within 45 degree of the falling direction of the previous domino.

The direction of falling is the relative position of it to the previous fallen domino. No two dominoes will cause the same domino to fall over simultaneously. See the following example for more details.

XXX
XXX
XXX
We say the outer 8 dominoes are adjacent with the middle one. With a force to east on the middle domino, the 3 dominoes in the third column will fall over and the direction will be northeast, east, southeast. So the ending grid is :

XXY
XEE
XXQ
Input

There are multiple test cases. Each case begins with a line containing two positive integer n and m (1 <= n, m <= 500) that are the number of rows and columns of the grid. The next n lines each with m chars (only '.' and 'X') describe one row of the grid. At last, two integers i, j (ith row, jth column, both i and j start from 1) indicate the location of the force and a char C describes the direction of the force. You can assume that there is a domino at the location (i, j).

Process to the end of file.

Output

Print the ending description of the grid, using the abbreviations for the fallen dominoes.

Print a blank line between cases.

Sample Input

2 4
..XX
XX..
1 3 S
4 4
XXX.
...X
X..X
XXX.
3 1 E
Sample Output

..SX
WJ..

WWV.
...N
E..Y
XQE.

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-17 15:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题