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 ...
随机推荐
- NPOI 2.0 教程(二):编辑既存的EXCEL文件
NPOI 2.0 教程(二):编辑既存的EXCEL文件 分类: C#技术 2014-03-11 15:40 993人阅读 评论(3) 收藏 举报 c#excelNPOI 转载请注明出处 http:// ...
- 微信小程序实例教程(一)
序言 开始开发应用号之前,先看看官方公布的「小程序」教程吧!(以下内容来自微信官方公布的「小程序」开发指南) 本文档将带你一步步创建完成一个微信小程序,并可以在手机上体验该小程序的实际效果.这个小程序 ...
- Recover Polygon (easy)
Recover Polygon (easy) The zombies are gathering in their secret lair! Heidi will strike hard to des ...
- 使用jquery模拟键盘事件,但window系统并不会真的响应事件,只是浏览器当前页面会响应而已
<!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv= ...
- js选择一个选项 跳出另一个选项 跳出一个输入框
跳出输入框 <script language="javascript"> function $(obj){return document.getElementById( ...
- Eclipse/MyEclipse 最最常用的快捷键
F 键类 F2 显示详细信息 F3 跳到声明或定义的地方 Ctrl + 键类 Ctrl+1 快速修复 ( 最经典的快捷键 , 就不用多说了 ) Ctrl+D 删除当前行 Ctrl+E 快速显示当前 E ...
- DOS日期和时间 - Robin Hu的专栏 - 博客频道 - CSDN.NET
body { font-family: Microsoft YaHei UI,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-ser ...
- JavaScript中call,apply,bind方法的总结
原文链接:http://www.cnblogs.com/pssp/p/5215621.html why?call,apply,bind干什么的?为什么要学这个? 一般用来指定this的环境,在没有学之 ...
- js学习之函数
1/.js中函数就是对象. 2/以表达式方式定义的函数一般不要函数名以使代码紧凑. 3/js中函数声明的方式会被默认提到外部脚本或最前面,所以在其定义前的代码也可调用. 然而以表达式方式的则不行. 4 ...
- git diff 差异对比
转载原文: http://fsjoy.blog.51cto.com/318484/245465/ 1. 查看当前所有的更改情况.git status 结果有3部分,changes to be comm ...