标签:
Time Limit: 5000MS | Memory Limit: 65536K | |||
Total Submissions: 9948 | Accepted: 3726 | Special Judge |
Description
Input
Output
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
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> #include<vector> #include<stack> using namespace std; int n,m,p; char s[1010][1010],tt[1010]; int mp[1010][1010],next[1000010][27],cnt,endd[1000010],ansx[1010],ansy[1010]; char ansd[1010]; const int dx[8]={-1,-1,0,1,1,1,0,-1}; const int dy[8]={0,1,1,1,0,-1,-1,-1}; void insertt(int x) { int temp=0,alp; scanf("%s",tt); for(int i=0;tt[i];i++) { alp=tt[i]-‘A‘; if(!next[temp][alp]) next[temp][alp]=++cnt; temp=next[temp][alp]; } endd[temp]=x; } void findd(int sx,int sy,int dic) { int temp=0,alp,x=sx,y=sy,e; while(next[temp][alp=mp[x][y]]) { temp=next[temp][alp]; e=endd[temp]; if(e) ansx[e]=sx,ansy[e]=sy,ansd[e]=dic; x=x+dx[dic]; y=y+dy[dic]; if(x<0||x>=n||y<0||y>=m) return ; } } int main() { while(scanf("%d%d%d",&n,&m,&p)!=EOF) { cnt=0; for(int i=0;i<n;i++) scanf("%s",s[i]); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { mp[i][j]=s[i][j]-‘A‘; } } for(int i=1;i<=p;i++) insertt(i); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { for(int k=0;k<8;k++) findd(i,j,k); } } for(int i=1;i<=p;i++) printf("%d %d %c\n",ansx[i],ansy[i],ansd[i]+‘A‘); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4385676.html