当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3434:Terrarium

题目描述

A zoology research lab has a terrarium with rare species of snakes. Terrarium is a flat box filled with soil, and has a glass top allowing to watch the snakes. There are trenches in the soil, and snakes constantly move along the trenches. All snakes have diameter of 1 cm and integer length of no less than 2 cm.

While watching the snakes, the zoologists discovered a pattern in their movement: each snake moves at a speed of 1 cm per second forward, until it encounters either a wall or another snake. Faced an obstacle, snake first tries to turn right, if there is also obstacle on the right, then it tries to turn left. If there is obstacle on the left also, the snake waits for a second before trying to move again.

In order to validate the discovery, it was decided to write a program that simulates snakes' behaviour. This task was assigned to you.

The terrarium is represented by an array of N × N characters. Each character is one of:

  • '.' (ASCII 46) — trench
  • '#' (ASCII 35) — wall
  • 'A' to 'Z' — snake's head
  • 'a' to 'z' — snake's body or tip of the tail

Snakes are represented by Latin letters, so there are no more than 26 snakes in terrarium. Snakes try to move in alphabetical order every second.

Your program must output the state of the terrarium after T seconds.

输入解释

First line of input file contains integers N T. Following N lines contain N characters each — the initial state of the terrarium. The input file guarantees unambiguous recognition of snakes — all snakes are continuous, every character of snake's body has exactly two neighbour characters belonging to the same snake, while head and tip of the tail have exactly one.

Constraints

2 ≤ N ≤ 1000, 1 ≤ T ≤ 106.

输出解释

Output file must contain N lines of N characters — the state of the terrarium after T seconds.
 

输入样例
Sample input 1
4 8
.bB.
....
a.#.
aaA.
Sample input 2
7 100000
aA.....
a#####D
aa....d
......d
......d
......d
.......
输出样例
Sample output 1
.baa
.BAa
..#.
....
Sample output 2
aaaaADd
.#####d
......d
......d
.......
.......
.......
提示
Bold texts appearing in the sample sections are informative and do not form part of the actual data.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3434

最后修改于 2020-10-29T07:01:31+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536