Zju1290 Word-Search Wonder(http://begin.lydsy.com/JudgeOnline/problem.php?id=2768)
2768: Zju1290 Word-Search Wonder
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 4 Solved: 2
[Submit][Status][Web Board]
Description
``Hi, guys,'' she replied. ``What are you doing, Wade?'' she asked her nephew. He was busy working on one of the restaurant's activity sheets with a crayon.
``I'm doing a word search game,'' Wade explained. ``I have to find all of these words in this big mess of letters. This is really hard.'' Wade looked intently at the paper in front of him.
``Can I help?'' asked Valentine, looking across the table at the activity sheet.
``Sure. These are the words we're looking for. They're the names of different kinds of Planes, Trains, and Automobiles.''
在字母矩阵找找单词游戏,找的方向有8个,水平、垂直、两个对角线,外加每种两个方向。求给定的词是否在字母矩阵中,并求开始和结束的坐标。
Input
A list of words will follow. Each word will be on a line by itself; there will be 100 or fewer words. Each word will be 100 or fewer characters long, and will only contain uppercase letters.
The final line of input will contain a single zero character.
Output
If a word is not found, the string ``Not found'' should be output instead of a pair of coordinates.
Each word from the input can be ``found'' at most once in the puzzle.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
1 5
EDEEE
DISKE
ESEEE
ECEEE
EEEEE
DISC
DISK
DISP
0
Sample Output
1,2 4,2
2,1 2,4
Not found
HINT
Source
题解:
分类是trie树,写了一个dfs过了,醉!
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[][],s[];
int n,m,i,j;
int x1,y1,x2,y2;
bool dfs(int deep,int x,int y,int dx,int dy)
{
if (deep>strlen(s+)){x2=x-dx; y2=y-dy; return true;}
if (x>n || x<= || y>n|| y<=) return false;
if (a[x][y]!=s[deep]) return false;
return dfs(deep+,x+dx,y+dy,dx,dy);
}
bool find (char *s)
{
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
if (a[i][j]==s[])
{
for (int k=-; k<=; k++)
for (int kk=-; kk<=; kk++)
if (k!= || kk!=)
if (dfs(,i,j,k,kk))
{
x1=i; y1=j; return true;
}
}
return false;
}
void work()
{
cin>>n;
for (int i=; i<=n; i++) for (int j=; j<=n; j++) cin>>a[i][j];
while (true)
{
scanf("%s",s+);
if (s[]=='') break;
if (find(s)) cout<<x1<<','<<y1<<' '<<x2<<','<<y2<<endl; else cout<<"Not found"<<endl;
}
}
int main()
{
work();
}
Zju1290 Word-Search Wonder(http://begin.lydsy.com/JudgeOnline/problem.php?id=2768)的更多相关文章
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)
2770: PKU2503 Babelfish Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2 Solved: 2[Submit][Status][ ...
- http://begin.lydsy.com/JudgeOnline/problem.php?id=2774(poi病毒)
2774: Poi2000 病毒 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 5 Solved: 4[Submit][Status][Web Boa ...
- Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- LeetCode: Word Search 解题报告
Word SearchGiven a 2D board and a word, find if the word exists in the grid. The word can be constru ...
- [LeetCode] Word Search II 词语搜索之二
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- [LeetCode] Word Search 词语搜索
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- Leetcode: word search
July 6, 2015 Problem statement: Word Search Given a 2D board and a word, find if the word exists in ...
- Word Search I & II
Word Search I Given a 2D board and a word, find if the word exists in the grid. The word can be cons ...
- 【leetcode】Word Search
Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constr ...
随机推荐
- Python 数据挖掘 工具包整理
连接器与io 数据库 类别 Python R MySQL mysql-connector-python(官方) RMySQL Oracle cx_Oracle ROracle MongoDB pymo ...
- JSP内置对象--web安全性及config对象的使用 (了解即可)
tomcat服务器配置的时候,在虚拟目录中必须存在一个WEB-INF文件夹,但是访问的时候并不能发现这个文件夹.改成WEB-INFs就可以看到. 所以WEB-INF文件夹不轻易让用户看到,那么其安全性 ...
- java输出日期时间
Calendar类下方法 c.add(Calendar.YEAR,4);//加4年 c.add(Calendar.MONTH,-1);// 月份减1 c.set(2012,2,23); //把时间设置 ...
- DIL中基本数据类型
(1)基本数据类型:OMG IDL基本数据类型包括short.long和相应的无符号(unsigned)类型,表示的字长分别为16.32位. (2)浮点数类型:OMG IDL浮点数类型包括float ...
- zf-关于邵阳市打印模块个别单号打印之后不会跳转到收费模块的BUG的解决方法
原因是 办结的时候 有个收费管理,里面会生成收费项目的单号,但是有1个单号是有问题的,没有关联到数据库里面的其他的表,所以打印之后不能跳转.如果跳转到收费模块 那么数据库里面的一个flag字段会变成9 ...
- VI中的批量替换 (转载)
1) 文件内全部替换: :%s#abc#123#g (如文件内有#,可用/替换,:%s/abc/123/g) --注:把abc替换成123 (或者: %s/str1/str2/g 用s ...
- CentOS6.5 安装snorby
如果下列任何组件之一已经被安装,请酌情忽略 1.Snort 参照 CentOS6.5 安装snort 2.GIT 系统自带 3.Ruby 版本限制> 1.9.2 系统自带版本过低首先卸载掉,注意 ...
- Android PopupWindow的使用技巧(转)
Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...
- Python3基础 定义无参数无返回值函数 调用会输出hello world的函数
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- PHP 将MySQL数据导出csv
1.查询数据 // 假设得到的数据格式如下 $result = array( array( "orderid" = "1110111", "shopi ...