Background
Given an m by n grid of letters and a list of words, find the location in the grid at which the word can be found.
A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e., upper- and lowercase letters are to be treated as the same). The matching can be done in any of the eight horizontal,
vertical, or diagonal directions through the grid.
Input
The input begins with a single positive integer on a line by itself indicating the number of cases, followed by a blank line. There is also a blank line between each two consecutive cases.
Each case begins with a pair of integers m followed by n on a single line, where 1 ≤ m, n ≤ 50 in decimal notation. The next m lines contain n letters each, representing the grid of letters where the words must be found. The letters in the grid may be in
upper- or lowercase. Following the grid of letters, another integer k appears on a line by itself (1 ≤ k ≤ 20). The next k lines of input contain the list of words to search for, one word per line. These words may contain upper- and lowercase letters only
– no spaces, hyphens, or other non-alphabetic characters.
Output
For each word in each test case, output a pair of integers representing its location in the corresponding grid. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given word can be found
(1 represents the topmost line in the grid, and m represents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid, and n represents the rightmost
column in the grid). If a word can be found more than once in the grid, then output the location of the uppermost occurrence of the word (i.e., the occurrence which places the first letter of the word closest to the top of the grid). If two or more words are
uppermost, output the leftmost of these occurrences. All words can be found at least once in the grid.
The output of two consecutive cases must be separated by a blank line.
Source
http://online-judge.uva.es/p/v100/10010.html
测试输入
期待的输出
时间限制
内存限制
额外进程
测试用例 1
以文本方式显示
-
1↵
-
↵
-
811↵
-
abcDEFGhigg↵
-
hEbkWalDork↵
-
FtyAwaldORm↵
-
FtsimrLqsrc↵
-
byoArBeDeyv↵
-
Klcbqwikomk↵
-
strEBGadhrb↵
-
yUiqlxcnBjf↵
-
4↵
-
Waldorf↵
-
Bambi↵
-
Betty↵
-
Dagbert↵
|
以文本方式显示
|
1秒 |
64M |
0 |
这道题目的关键是如何找到单词的第一个字母在矩阵中的位置并遍历8个方位,找到合适的匹配,方法很简单,关键是要考虑周全:
分享到:
相关推荐
ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛ACM大赛
从ACM的介绍和竞赛规则开始,逐步介绍了如何准备ACM竞赛,包括学习编程基础、算法和数据结构、练习编程题目、团队协作以及参加模拟竞赛。博客还提供了ACM竞赛的挑战和收获,如提高编程技能、团队协作能力、国际交流...
ACM ACM ACM ACM ACM讲义.ppt
ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板AACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM 模板ACM ...
ACM PRO ACM PROACM PRO ACM PROACM PRO ACM PRO
包含近几年多道ACM面试题目,希望有所帮助
acm模板acm模板acm模板acm模板acm模板acm模板acm模板acm模板
ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码ACM常用代码
acm经典题库acm经典题库acm经典题库
ACM地址 ACM地址 ACM地址 ACM地址 ACM地址
ACM大数模版ACM大数模版ACM大数模版ACM大数模版ACM大数模版ACM大数模版ACM大数模版ACM大数模版
ACM练习建议 ACM练习建议 ACM练习建议
上海交大ACM模板 考研复试机试参考资料
acm课件1acm课件1acm课件1acm课件1acm课件1acm课件1acm课件1acm课件1acm课件1
杭电ACM分类杭电ACM分类杭电ACM分类杭电ACM分类
ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM各种练习题ACM...
ACM培训资料 ACM培训资料 ACM培训资料 ACM培训资料
北大ACM分类,北大ACM分类 北大ACM分类
几个ACM题的答案,对参加ACM竞赛非常有用,这几个题很经典的,一般参加ACM的都会拿这几个题练手的!