POJ 1204 Word Puzzles (AC自動機)
來源:程序員人生 發布時間:2015-04-11 09:46:24 閱讀次數:3006次
Word Puzzles
Time Limit: 5000MS |
|
Memory Limit: 65536K |
Total Submissions: 9926 |
|
Accepted: 3711 |
|
Special Judge |
Description
Word puzzles are usually simple and very entertaining for all ages. They are so entertaining that Pizza-Hut company started using table covers with word puzzles printed on them, possibly with the intent to minimise their client's
perception of any possible delay in bringing them their order.
Even though word puzzles may be entertaining to solve by hand, they may become boring when they get very large. Computers do not yet get bored in solving tasks, therefore we thought you could devise a program to speedup (hopefully!) solution finding in such
puzzles.
The following figure illustrates the PizzaHut puzzle. The names of the pizzas to be found in the puzzle are: MARGARITA, ALEMA, BARBECUE, TROPICAL, SUPREMA, LOUISIANA, CHEESEHAM, EUROPA, HAVAIANA, CAMPONESA.
Your task is to produce a program that given the word puzzle and words to be found in the puzzle, determines, for each word, the position of the first letter and its orientation in the puzzle.
You can assume that the left upper corner of the puzzle is the origin, (0,0). Furthemore, the orientation of the word is marked clockwise starting with letter A for north (note: there are 8 possible directions in total).
Input
The first line of input consists of three positive numbers, the number of lines, 0 < L <= 1000, the number of columns, 0 < C <= 1000, and the number of words to be found, 0 < W <= 1000. The following L input lines, each one of
size C characters, contain the word puzzle. Then at last the W words are input one per line.
Output
Your program should output, for each word (using the same order as the words were input) a triplet defining the coordinates, line and column, where the first letter of the word appears, followed by a letter indicating the orientation
of the word according to the rules define above. Each value in the triplet must be separated by one space only.
Sample Input
20 20 10
QWSPILAATIRAGRAMYKEI
AGTRCLQAXLPOIJLFVBUQ
TQTKAZXVMRWALEMAPKCW
LIEACNKAZXKPOTPIZCEO
FGKLSTCBTROPICALBLBC
JEWHJEEWSMLPOEKORORA
LUPQWRNJOAAGJKMUSJAE
KRQEIOLOAOQPRTVILCBZ
QOPUCAJSPPOUTMTSLPSF
LPOUYTRFGMMLKIUISXSW
WAHCPOIYTGAKLMNAHBVA
EIAKHPLBGSMCLOGNGJML
LDTIKENVCSWQAZUAOEAL
HOPLPGEJKMNUTIIORMNC
LOIUFTGSQACAXMOPBEIO
QOASDHOPEPNBUYUYOBXB
IONIAELOJHSWASMOUTRK
HPOIYTJPLNAQWDRIBITG
LPOINUYMRTEMPTMLMNBO
PAFCOPLHAVAIANALBPFS
MARGARITA
ALEMA
BARBECUE
TROPICAL
SUPREMA
LOUISIANA
CHEESEHAM
EUROPA
HAVAIANA
CAMPONESA
Sample Output
0 15 G
2 11 C
7 18 A
4 8 C
16 13 B
4 15 E
10 3 D
5 1 E
19 7 C
11 11 H
Source
Southwestern Europe 2002
題目鏈接:http://poj.org/problem?id=1204
題目大意:給1個字符矩陣,和1些單詞,求這些單詞的首字母的位置和單詞的方向,1共8個方向,正北為A,順時針BCD...
題目分析:對單詞建立trie樹,構造ac自動機,以4個邊上的字符為出發點向8個方向枚舉找
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
int const MAX = 1005;
char map[MAX][MAX], s[MAX];
int r, c, n;
int len[MAX], ans[MAX][3];
int dx[8] = {⑴, ⑴, 0, 1, 1, 1, 0, ⑴};
int dy[8] = {0, 1, 1, 1, 0, ⑴, ⑴, ⑴};
struct node
{
int id;
node *next[26];
node *fail;
node()
{
id = ⑴;
memset(next, NULL, sizeof(next));
fail = NULL;
}
};
void Insert(node *p, char *s, int id)
{
for(int i = 0; s[i] != '
主站蜘蛛池模板:
欧美成人一区二区
|
强公把我次次高潮hd
|
国产二区电影
|
麻豆精品网站
|
欧美日韩精品一区二区三区蜜桃
|
国产精品精品久久久久久
|
国产精品黄色片
|
黄色毛片视频在线观看
|
国产影院av
|
国产精品久久久一区麻豆最新章节
|
欧美精品成人
|
久久一区国产
|
国产激情在线观看
|
欧美亚洲在线
|
99精品国产热久久91蜜凸
|
亚洲男人天堂2024
|
欧美在线一区二区三区
|
欧美成人精品二区三区99精品
|
欧美视频一区二区三区
|
欧美一区二区网站
|
国产日韩精品视频
|
国产精品二
|
亚洲欧美精品
|
免费黄看片
|
小草av在线
|
久久精品不卡
|
国产iv一区二区三区
|
国产午夜视频在线观看
|
一区二区三区91
|
欧美激情视频在线播放
|
日韩av免费在线观看
|
国产免费小视频
|
成人福利午夜
|
久久se精品一区精品二区
|
9999精品|
国产成人综合久久
|
www.成人在线视频
|
欧美日韩国
|
欧美成人在线网站
|
日韩 国产 在线
|
老色批av
|