Time Limit: 5000MS | Memory Limit: 65536K | |||
Total Submissions: 8894 | Accepted: 3342 | 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
这题够无语的,写出来了,然后有的样例没过,又检查了好久,妹妹啊!原来是可能有两个字符串同一棵子树,所以得继续搜下去。然后有一个是判断val[u]为不为真的时候然后才判断它们的坐标是否已经出界,就是在这WA得想放弃了……靠……想了想,觉得可能在出界之前val[u]可能为真就出错了,所以换了下顺序就过了……fuck!!!
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <list> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define PI acos(-1.0) #define mem(a,b) memset(a,b,sizeof(a)) #define sca(a) scanf("%d",&a) #define pri(a) printf("%d\n",a) #define lson i<<1,l,mid #define rson i<<1|1,mid+1,r #define MM 200205 #define MN 1005 #define INF 10000007 using namespace std; char str[MN][MN],ss[MN]; int val[MM],sz=1,vis[27],out[MN][3],x,y,n,m; int dis[8][2]={-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1,-1,-1}; struct Trie { int next[27]; } trie[MM]; int idx(char c) { return c-'A'; } void insert(char *s,int k) { int u=0,i,c,l=strlen(s); for(i=0; i<l; i++) { c=idx(s[i]); if(!trie[u].next[c]) trie[u].next[c]=sz++; u=trie[u].next[c]; } val[u]=k; } void dfs(int u,int i,int j,int q) { if(!u||i<0||i>=n||j<0||j>=m) return; //i<0之后的条件刚开始放在if(val[u])条件之后的,然后WA了6发,差点想暂时放弃了 if(val[u]) { out[val[u]][0]=x,out[val[u]][1]=y,out[val[u]][2]=q; val[u]=0; } int l=str[i+dis[q][0]][j+dis[q][1]]-'A'; //下一个搜索的是当前结点+下一个字母的结点,和insert原理相同 dfs(trie[u].next[l],i+dis[q][0],j+dis[q][1],q); } int main() { int p,i,j,k; scanf("%d%d%d",&n,&m,&p); for(i=0; i<n; i++) scanf("%s",str[i]); for(i=1; i<=p; i++) scanf("%s",ss),insert(ss,i),vis[ss[0]-'A']=1; for(i=0; i<n; i++) for(j=0; j<m; j++) if(vis[str[i][j]-'A']) for(k=0;k<8;k++) { x=i,y=j; dfs(trie[0].next[str[i][j]-'A'],i,j,k); } for(i=1;i<=p;i++) printf("%d %d %c\n",out[i][0],out[i][1],out[i][2]+'A'); return 0; }