点击打开链接题目链接
Word Puzzles
Time Limit: 5000MS | Memory Limit: 65536K | |||
Total Submissions: 9382 | Accepted: 3500 | 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).
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
给出一张地图 八个方向搜 输出字符串的起点坐标和方向
注意 不是输入一个字符串输出一个答案 而是输入结束之后全部一起按照顺序输出
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
struct node
{
int next[26];
int id;
}trie[120000];
int x,y;
char mark[1010][1010];
int dx[8]={-1,-1,0,1,1,1,0,-1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
int head;
int ans[1010][3];
int m,n;
void tree_add(char *str,int ids)
{
int s=0;
int i,l;
l=strlen(str);
int w;
for(i=0;i<l;i++)
{
w=str[i]-'A';
if(trie[s].next[w]==-1)
{
trie[s].next[w]=++head;
}
s=trie[s].next[w];
}
trie[s].id=ids;
}
void dfs(int p,int a,int b,int dis)
{
int w;
w=mark[a][b]-'A';
if(p==-1)
return;
if(trie[p].id>0)
{
ans[trie[p].id][0]=x;
ans[trie[p].id][1]=y;
ans[trie[p].id][2]=dis;
trie[p].id=0;
}
if(a<0||a>=n||b<0||b>=m)
return ;
dfs(trie[p].next[w],a+dx[dis],b+dy[dis],dis);
}
/*void tree_output(char *str)
{
int s=0;
int i,l,w;
l=strlen(str);
for(i=0;i<l;i++)
{
w=str[i]-'A';
printf("%d\n",trie[s].id);
s=trie[s].next[w];
}
printf("%d\n",trie[s].id);
}*/
int main()
{
int t;
int i,j,k;
char str[1010];
while(scanf("%d%d%d",&n,&m,&t)!=EOF)
{
head=0;
for(i=0;i<120000;i++)
{
trie[i].id=0;
for(j=0;j<26;j++)
{
trie[i].next[j]=-1;
}
}
for(i=0;i<n;i++)
{
scanf("%s",mark[i]);
}
for(i=1;i<=t;i++)
{
scanf("%s",str);
tree_add(str,i);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<8;k++)
{
x=i;
y=j;
dfs(0,i,j,k);
}
}
}
for(i=1;i<=t;i++)
{
printf("%d %d %c\n",ans[i][0],ans[i][1],ans[i][2]+'A');
}
}
return 0;
}