博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 题目1204 Word Puzzles(AC自己主动机,多个方向查询)
阅读量:4328 次
发布时间:2019-06-06

本文共 4899 字,大约阅读时间需要 16 分钟。

Word Puzzles
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 10244   Accepted: 3864   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 10QWSPILAATIRAGRAMYKEIAGTRCLQAXLPOIJLFVBUQTQTKAZXVMRWALEMAPKCWLIEACNKAZXKPOTPIZCEOFGKLSTCBTROPICALBLBCJEWHJEEWSMLPOEKORORALUPQWRNJOAAGJKMUSJAEKRQEIOLOAOQPRTVILCBZQOPUCAJSPPOUTMTSLPSFLPOUYTRFGMMLKIUISXSWWAHCPOIYTGAKLMNAHBVAEIAKHPLBGSMCLOGNGJMLLDTIKENVCSWQAZUAOEALHOPLPGEJKMNUTIIORMNCLOIUFTGSQACAXMOPBEIOQOASDHOPEPNBUYUYOBXBIONIAELOJHSWASMOUTRKHPOIYTJPLNAQWDRIBITGLPOINUYMRTEMPTMLMNBOPAFCOPLHAVAIANALBPFSMARGARITAALEMABARBECUETROPICALSUPREMALOUISIANACHEESEHAMEUROPAHAVAIANACAMPONESA

Sample Output

0 15 G2 11 C7 18 A4 8 C16 13 B4 15 E10 3 D5 1 E19 7 C11 11 H

Source

题目大意:给你一个矩阵,然后问每一个串在矩阵中的起点和方向,方向从上(A)顺时针8个方向

就是也8个方向的查询就好。。

ac代码

#include
#include
char map[1010][1010],key[1010];int dx[8]={-1,-1,0,1,1,1,0,-1};int dy[8]={0,1,1,1,0,-1,-1,-1};int ansx[1010],ansy[1010],ansd[1010],len[1010];int head,tail;int n,m,w;struct node { node *fail; node *next[26]; int id; node() { fail=NULL; id=0; for(int i=0;i<26;i++) next[i]=NULL; } }*q[50005000]; node *root; void insert(char *s,int id) { int temp,len,i; node *p=root; len=strlen(s); for(i=0;i
next[temp]==NULL) p->next[temp]=new node(); p=p->next[temp]; } p->id=id; } void build_ac() { head=tail=0; q[tail++]=root; while(head!=tail) { node *p=q[head++]; node *temp=NULL; for(int i=0;i<26;i++) { if(p->next[i]!=NULL) { if(p==root) p->next[i]->fail=root; else { temp=p->fail; while(temp!=NULL) { if(temp->next[i]!=NULL) { p->next[i]->fail=temp->next[i]; break; } temp=temp->fail; } if(temp==NULL) { p->next[i]->fail=root; } } q[tail++]=p->next[i]; } } } }void query(int x,int y,int dir){ node *p=root,*temp; int i,j; for(i=x,j=y;i>=0&&i
=0&&j
next[x]==NULL&&p!=root) p=p->fail; p=p->next[x]; if(p==NULL) { p=root; } temp=p; while(temp!=root&&temp->id!=-1) { int id=temp->id; ansx[id]=i-(len[id]-1)*dx[dir]; ansy[id]=j-(len[id]-1)*dy[dir]; ansd[id]=dir; temp->id=-1; temp=temp->fail; } }}int main(){// int n,m,w; while(scanf("%d%d%d",&n,&m,&w)!=EOF) { int i,j; root=new node(); for(i=0;i

转载于:https://www.cnblogs.com/liguangsunls/p/7237676.html

你可能感兴趣的文章
Windows之IOCP
查看>>
机器学习降维之主成分分析
查看>>
CTP2交易所成交回报
查看>>
WebSocket & websockets
查看>>
openssl 升级
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------&gt;Android嵌入图像InsetDrawable的使用方法
查看>>
Detours信息泄漏漏洞
查看>>
win32使用拖放文件
查看>>
Android 动态显示和隐藏软键盘
查看>>