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 ...
随机推荐
- Java的SSH框架
SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架. 1.业务流程 集成SSH框架的系统从职责上分为四层:表示层.业务逻辑层.数据 ...
- win7 系统保留分区 BCDedit
系统保留分区简介编辑 “系统保留”分区示意图 Windows Vista/7出于安全考虑,在新装Windows Vista/7系统过程中,如果利用光盘的分区工具给硬盘分区时,系统默认的将一部分(100 ...
- Java 错误:找不到或无法加载主类
环境变量的配置有问题,你改改吧:HOME是 D:\Java\jdk1.8.0_11 Path是 %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin CLASSPATH是 .;%JA ...
- javascript OOP 面向对象编程
Pseudo-class declaration 原文地址:http://javascript.info/tutorial/pseudo-classical-pattern#pseudo-class- ...
- 超级素数(sprime)
超级素数(sprime) 题目描述 超级素数是指一个素数,每去掉后面一个数字,总能保证剩下的数为质数,例如:373->37->3这是一个长为3的超级素数. 输入 输入一个整数n (10≤n ...
- CodeForces 605B Lazy Student
构造.对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面. 然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连. #include<cstd ...
- codeforce 611A New Year and Days
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- 【poj解题】1308
判断一个图是否是一个树,树满足一下2个条件即可:1. 边树比node数少12. 所有node的入度非0即1 节点数是0的时候,空树,合法树~ 代码如下 #include <stdio.h> ...
- (简单) HDU 2612 Find a way,BFS。
Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...
- 《Android学习指南》目录
源:<Android学习指南>目录 Android学习指南的内容分类: 分类 描述 0.学习Android必备的Java基础知识 没有Java基础的朋友,请不要先看Android的课程,这 ...