poj1204 字典树+DFS
来源:互联网 发布:mac版cad2014破解文件 编辑:程序博客网 时间:2024/04/28 07:29
#include<stdio.h>#include<string.h>const int N = 1008;const int CAP = 150;char stc[N][N];char word[N];int res[N][3];int dir[8][2]={0, -1, 1, -1, 1, 0, 1, 1, 0, 1, -1, 1, -1, 0, -1, -1};int root;int px, py;int l, c, w;struct Trie{ int next[CAP]; int id; void init() { memset(next, -1, sizeof(next)); id = 0; }};Trie node[N*100];int size;void myinsert(char* str, int id){ int len = strlen(str); int i = 0, p = 0; while(i < len) { if(node[p].next[str[i]] == -1) { node[p].next[str[i]] = size; node[size++].init(); } p = node[p].next[str[i]]; i++; } node[p].id = id;}void dfs(int cur, int x, int y, int d){ if(cur == -1) return; int t = node[cur].id; if(t > 0) { res[t][0] = px, res[t][1] = py, res[t][2] = d + 'A'; } if(x < 0 || x >= l || y < 0 || y >= c) return; dfs(node[cur].next[stc[x][y]], x + dir[d][1], y + dir[d][0], d);}//void init(){ root = 0; node[0].init(); size = 1;}int main(){ while(~scanf("%d%d%d", &l, &c, &w)) { init(); for(int i = 0; i < l; i++) scanf("%s", stc[i]); for(int i = 1; i <= w; i++) { scanf("%s", word); myinsert(word, i); } for(int i = 0; i < l; i++) { for(int j = 0; j < c; j++) { for(int k = 0; k < 8; k++) { px = i, py = j; dfs(0, i, j, k); } } } for(int i = 1; i <= w; i++) printf("%d %d %c\n", res[i][0], res[i][1], res[i][2]); } return 0;}
当数组大小为 100 * 1008 * 256 会超 65535K 的内存
最多大概能开到 100 * 1008 * 150
0 0
- poj1204 字典树+DFS
- poj1204字典树+dfs搜索
- 【字典树】 poj1204 Word Puzzles
- POJ1204 - Word Puzzles - 字典树
- POJ1204
- la4670 字典树+dfs
- hdu1298(字典树+dfs)
- 【字典树+DFS】 hdu1298 T9
- HDU 1298 字典树+DFS
- 词频统计:字典树+dfs
- POJ 3764(dfs+字典树)
- HDU1298 T9 字典树+DFS
- UVALive 7043 字典树+DFS
- POJ 1816 字典树+DFS
- HDU 4776 DFS + 字典树
- hdu1298(字典树+dfs)
- POJ 1451 字典树+DFS + 剪枝
- HDU 1298 T9 字典树+dfs
- Oracle set unused的用法
- Android 软键盘遮挡三种解决方案
- IE下载docx(xlsx,pptx)文件时,会自动将扩展名变为zip
- PCB任意角度和距离放置元器件
- Qt将excel导入到QTableView
- poj1204 字典树+DFS
- R语言面向对象指南
- Codeforces Round #Pi (Div. 2)
- android studio 新建项目 界面一直停在 【“building ‘ 项目名’ gradle project info”】
- map unordered_map hash_map比一比
- LayoutInflater原理分析,View工作原理(一)
- ShowPopupMenu显示自己创建的右键菜单 不显示
- 学习java前一些概念的说明
- MBProgressHUD在多线程里面使用