大意:給出一個棋盤puzzle,,和w個模式串,,在棋盤中尋找模式串。。棋盤中任意一格有8個方向可以走。。
解題思路: ac自動機 + 列舉8個方向即可
get_trie(),get_ac().直接用模版。。。。
query 有一點小技巧。。需要列舉8個方向,,對於一行,我們對豎直方向上的列舉可以省略,因為我們在豎直方向上列舉時,會補充上。。
另外 我們無需列舉一行中的每一個點,,只需第一個即可,因為,,我們在一個方向上列舉時,,會包含到後面的。
1 #include 2 #include3using
namespace
std;
4struct
point
14 }*q[5000005
];//bfs 獲得fail 用
1516
struct
pos;
19 pos ans[1005
];20 point *root =null;
21int
l,c,w;
22char map[1005][1005];//
puzzle
23char str[1005];//
模版串24
int len[1005];//
記錄每個摸版的長度
25int
tail,head;
26int dix[8][2] = ;//
順時針,,上下左右。。。八個方向
27char res[9]=;
28void build_trie(char *str,int
id)37 p->istail = true
;38 p->id =id;39}
40void
get_ac()
57 p = p->fail;58}
59if(p==null) temp->next[i]->fail =root;60}
61 q[head++] = temp->next[i];62}
63}64}
65}6667
void query(int x,int y,int
i)85 qq = qq->fail;86}
87}88}
89int
main()
90100 head = tail =0
;101
get_ac();
102for(int i=1;i<=l;i++)
106for(int i=0;i)
110111
for(int i=0;i)
114return0;
115 }
POJ1204 Word Puzzles 題解
題目大意 給一個字母表,求一些字串的開端第一次出現的位置和字串的方向 字串可以按照八個方向放在字母表中可匹配的位置 一定是ac自動機,而且我們不可能對二位字母表ac一下,所以我們要把待匹配串ac一下,然後列舉字母表的起點 不要列舉多了 ,accheck一下就好了,蠻裸的。 為了保證最小序,需要...
codevs 1204
1204 尋找子串位置 題目描述 description 給出字串a和字串b,保證b是a的一個子串,請你輸出b在a中第一次出現的位置。 輸入...
ZOJ 1204 DFS
輸出一串數所能構成的所有等式,按照加數從大到小,算式從長到短排列 一開始因為無法按照要求輸出糾結了好一陣 最後看了大神的 才發現只需要每次dfs規定長度就好了 include cstdio include cstring include algorithm define maxn 40 using ...