CF106D.Treasure Island
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle n × m in size. Each cell stands for an islands' square (the square's side length equals to a mile). Some cells stand for the sea and they are impenetrable. All other cells are penetrable (i.e. available) and some of them contain local sights. For example, the large tree on the hills or the cave in the rocks.
Besides, the map also has a set of k instructions. Each instruction is in the following form:
"Walk n miles in the y direction"
The possible directions are: north, south, east, and west. If you follow these instructions carefully (you should fulfill all of them, one by one) then you should reach exactly the place where treasures are buried.
Unfortunately the captain doesn't know the place where to start fulfilling the instructions — as that very piece of the map was lost. But the captain very well remembers that the place contained some local sight. Besides, the captain knows that the whole way goes through the island's penetrable squares.
The captain wants to know which sights are worth checking. He asks you to help him with that.
我们的勇敢旅行者抵达了一座海盗埋藏宝藏的岛屿。然而,当船只即将靠岸时,船长发现一只老鼠啃掉了一块藏宝图。
这张藏宝图可表示为一个 n×m 的矩形。每个格子代表岛屿上的一个正方形区域(正方形边长为 1 英里)。某些格子代表海洋,不可通行;其余所有格子均可通行(即可用),其中部分格子包含当地景点,例如山丘上的大树或岩石中的洞穴。
此外,地图上还附有一组共 k 条指令。每条指令的形式如下:
“向 y 方向行走 n 英里”
可能的方向有:北(north)、南(south)、东(east)和西(west)。若严格按顺序依次执行全部这些指令,则最终必将抵达宝藏的确切埋藏地点。
不幸的是,船长并不知道应从地图上的哪一点开始执行指令——因为标有起点的那部分地图已被老鼠啃毁。但船长清楚地记得:起点处必定存在某个当地景点。此外,船长还知道整条行进路径均位于岛屿的可通行格子上。
船长希望知道哪些景点值得查验。他请求你协助完成这项任务。
输入格式
The first line contains two integers n and m (3 ≤ n, m ≤ 1000).
Then follow n lines containing m integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are marked with uppercase Latin letters from "A" to "Z". Not all alphabet letters can be used. However, it is guaranteed that at least one of them is present on the map. All local sights are marked by different letters.
The next line contains number k (1 ≤ k ≤ 105), after which k lines follow. Each line describes an instruction. Each instruction possesses the form "dir len", where dir stands for the direction and len stands for the length of the way to walk. dir can take values "N", "S", "W" and "E" for North, South, West and East correspondingly. At that, north is to the top, South is to the bottom, west is to the left and east is to the right. len is an integer from 1 to 1000.
第一行包含两个整数 n 和 m(3≤n,m≤1000)。
接下来是 n 行,每行包含 m 个整数,描述岛屿地图。字符 # 表示海洋;保证矩形边界上的所有格子均为海洋。字符 . 表示可通行但无景点的方格;景点则用大写拉丁字母 "A" 到 "Z" 标记。并非所有字母都会被使用,但保证地图上至少出现一个景点字母。所有本地景点均以互不相同的字母标记。
下一行包含一个整数 k(1≤k≤105),随后是 k 行,每行描述一条指令。每条指令的格式为 _dir_ _len_,其中 _dir_ 表示行走方向,_len_ 表示行走步数。_dir_ 可取值 "N"、"S"、"W" 或 "E",分别对应北(North)、南(South)、西(West)和东(East)。其中,北指向地图上方,南指向下方,西指向左方,东指向右方。_len_ 是一个介于 1 到 1000 之间的整数。
输出格式
Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes.
按字母顺序打印所有满足题目要求的本地景点,结果为一个不含任何分隔符的字符串。若无符合条件的景点,则输出 "no solution"(不带引号)。
输入输出样例
输入#1
6 10 ########## #K#..##### #.#..##.## #..L.#...# ###D###A.# ########## 4 N 2 S 1 E 1 W 2
输出#1
AD
输入#2
3 4 #### #.A# #### 2 W 1 N 2
输出#2
no solution
输入解题思路,AI测评打分。不知道怎么写?