uva10010
来源:互联网 发布:学通网络ps序列号 编辑:程序博客网 时间:2024/05/20 14:43
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951
10010 - Where's Waldorf?
Time limit: 3.000 seconds
Where'sWaldorf? Given a m by n grid ofletters, (), and a list of words, find the location in the gridat which the word can be found. A word matches a straight,uninterrupted line of letters in the grid. A word can match theletters in the grid regardless of case (i.e. upper and lower caseletters are to be treated as the same). The matching can be done inany of the eight directions either horizontally, vertically ordiagonally through the grid.
Input
The input begins with a single positive integer on a line byitself indicating the number of the cases following, each of themas described below. This line is followed by a blank line, andthere is also a blank line between two consecutive inputs.
The input begins with a pair of integers, m followed byn, in decimal notation on a single line. The nextm lines contain n letters each; this is the grid ofletters in which the words of the list must be found. The lettersin the grid may be in upper or lower case. Following the grid ofletters, another integerk appears on a line by itself (). The next klines of input contain the listof words to search for, one word per line. These words may containupper and lower case letters only (no spaces, hyphens or othernon-alphabetic characters).
Output
For each test case, the output must follow the descriptionbelow. The outputs of two consecutive cases will be separated by ablank line.
For each word in the word list, a pair of integers representingthe location of the corresponding word in the grid must be output.The integers must be separated by a single space. The first integeris the line in the grid where the first letter of the given wordcan be found (1 represents the topmost line in the grid, andm represents the bottommost line). The second integer is thecolumn in the grid where the first letter of the given word can befound (1 represents the leftmost column in the grid, and nrepresents the rightmost column in the grid). If a word can befound more than once in the grid, then the location which is outputshould correspond to the uppermost occurence of the word (i.e. theoccurence which places the first letter of the word closest to thetop of the grid). If two or more words are uppermost, the outputshould correspond to the leftmost of these occurences. All wordscan be found at least once in the grid.
Sample Input
18 11abcDEFGhigghEbkWalDorkFtyAwaldORmFtsimrLqsrcbyoArBeDeyvKlcbqwikomkstrEBGadhrbyUiqlxcnBjf4WaldorfBambiBettyDagbert
Sample Output
2 52 31 27 8
Miguel Revilla
2000-08-22这题以前做过了,不过当时不大理解。。这次理解多了。。嘻嘻。。。题意:找到字符串在字符矩阵里的位置,并输出其头字母的坐标。我们先找到首字母的位置,
然后按照八个方向当中的一个搜索,如果能找到完整的字符串,就输出坐标。与DFS每个点按照
八个方向搜索不同的是,这里只是按照一个方向一个方向地搜索。所以搜索函数也稍有不同。
此题必须从八个方向来查找,依次是从当前位置向左上方、上方、右上方、左边、右边、左下方、下方、右下方,由于本题的要求,这个查找顺序不能改变。
不过我试过几种搜索路径发现还是可以A。。。看来这题数据弱了。。
输出时,每组测试数据之间没有空行;在每组测试数据中,每种情况(case)之间才有空行。
The outputs of twoconsecutive cases will be separated by a blankline.
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctype.h>
#define MAXN 100
int cas,m,n,q;
int x=0,y=0;
char r[MAXN][MAXN];
//const int dx[]={-1,-1,0,1,1,-1,0,1};//搜索的方向最上top(correspond tothe uppermost) 然后是最左然后是右再最后是下
//const int dy[]={0,1,1,1,0,-1,-1,-1};//If two or more words areuppermost, the output should correspond to the leftmost
const int dx[]={-1,0,1,-1,1,-1,0,1};
const int dy[]={1,1,1,0,0,-1,-1,-1};
void search(const char*a,int &x,int&y)
{
}
int main()
{
}
- uva10010
- uva10010
- UVA10010
- UVA10010
- UVA10010
- uva10010
- uva10010--String
- ACM-uva10010
- PC110302/UVA10010
- uva10010 - Where's Waldorf?
- uva10010 - Where's Waldorf?
- UVa10010 Where's Waldorf?
- UVA10010 Where's Waldorf?
- uva10010 - Where's Waldorf?
- UVA10010 Where's Waldorf?
- UVa10010 - Where's Waldorf?
- UVA10010 - Where's Waldorf?
- uva10010 - Where's Waldorf?
- hdoj1002(大数相加)
- 区分Activity的四种加载模式
- poj2488(经典dfs)
- uva401(回文串)
- ofbiz主题风格包及注意项
- uva10010
- C# int 转 字符串 格式化 位数不足加0
- uva409(字符串)
- 字符串函数的使用
- uva10361(字符串)
- uva10878(字符串)
- uva10115
- uva10815
- uva424(大数)